Trailing catch on function?

Anonymouse via Digitalmars-d digitalmars-d at puremagic.com
Tue Nov 8 03:24:59 PST 2016


On Tuesday, 8 November 2016 at 01:50:26 UTC, Walter Bright wrote:
>> Who to get the Exception thrown in the scope(failure)
>
> You don't. The exception is also rethrown, so it isn't an exact 
> replacement. (The 'nothrow' is a mistake on my part.)

You can eat the exception by returning in the scope guard. Since 
it seems to trigger on Throwables it also eats Errors, sadly.

void fun() nothrow
{
     scope(failure)
     {
         // cleanup logic
         return;
     }

     throw new Exception("I don't get rethrown");
}


More information about the Digitalmars-d mailing list