void Func(void)
{
Handle h = GetResource("monkey");
if ( ! h ) return;
~ { FreeDevice(h); }
// The rest of the function goes here
}
Does anyone like my minimalistic simplistic syntax here? You don't need to include a header file nor write lambda syntax. Perhaps we could also make use of the 'throw' keyword to indicate how the scope was exited:
void Func(void)
{
Handle h = GetResource("monkey");
if ( ! h ) return;
~ { if throw FreeDevice(h); }
// The rest of the function goes here
}
In the above code snippet, FreeDevice only gets called if Func is exited by means of a thrown exception. The two keywords 'if throw' side by side would have a special meaning here.