scope guards

Jacob Carlborg via Digitalmars-d digitalmars-d at puremagic.com
Mon Aug 4 00:21:00 PDT 2014


On Monday, 4 August 2014 at 04:09:07 UTC, Manu via Digitalmars-d 
wrote:

> Almost all exceptions I throw are in relation to bad input 
> data, and they
> are to be caught at a slightly higher level of input 
> processing. My code
> has become try/catch-tastic, and I really don't like looking at 
> it.

Why does it matter it has a lot of try/catch-blocks.

> It rather sickens me and reminds me of Java

So just because your code looks like Java you want to come up 
with a new feature that is exactly like "catch", but with a new 
name. Instead your code will become scope-tastic (whatever that 
means) and it doesn't look like Java because it use a different 
keyword.

> , and I'm strongly tempted to just
> abandon my experiment and return to C-style error handling with 
> sentinel
> values.

I can't see how that will improve anything. Seems like you have 
some grudge against Java and don't won't your code to look like 
it.

> So... why not make scope guards more useful? It wouldn't be 
> hard.
> scope(failure, MyException e) is completely non-destructive, 
> and adds
> significant power to the concept.

I think it's better to support catch-blocks without a try-block. 
BTW, if I recall correctly, I have already proposed this and it 
was turned down.

> Yeah, I can't imagine a use for it either.

Logging perhaps.


More information about the Digitalmars-d mailing list