Trailing catch on function?

Anonymouse via Digitalmars-d digitalmars-d at puremagic.com
Sat Nov 12 04:17:35 PST 2016


On Wednesday, 9 November 2016 at 09:49:08 UTC, Daniel N wrote:
> On Tuesday, 8 November 2016 at 16:02:25 UTC, Manu wrote:
>> scope(failure) doesn't catch... how is that function nothrow?
>
> Seems like you overlooked Anonymouse's comment? scope(failure) 
> catches just fine.
>
> scope(failure) return -1;
> throw new Exception("failure");
> return 0;
>
> This will return -1, with no need for extra indentation.

I understand its convenience, but as long as it also catches 
Errors I'm not sure this is something you want to do though. You 
won't be able to differentiate between invalid input and bugs in 
the code, potentially continuing in an invalid state.

Subsetting failure into a scope(exception) would work, but I'm 
not sure how the interplay between them would work. Or are Errors 
so fatal that it should always immediately crash the program, 
ignored by scope(failure)?


More information about the Digitalmars-d mailing list