scope() statements and return

via Digitalmars-d digitalmars-d at puremagic.com
Sun Oct 5 09:30:46 PDT 2014


On Sunday, 5 October 2014 at 15:03:08 UTC, ketmar via 
Digitalmars-d wrote:
> so Error should not be catchable and should crash immidiately, 
> without
> any unwinding. as long as Errors are just another kind of 
> exception,
> the promise must be kept.

I find it strange if you cannot recover from out-of-memory-error. 
The common trick is to preallocate a bulk of memory, then free it 
when you throw the out of memory exception so that you can 
unwind. When destroying the out-of-memory-object you need to 
reallocate the bulk of memory.

I also find the D terminology confusing, one should avoid 
redefining terms.

Does D have exception chaining? The language spec seems to imply 
that finally swallows thrown exceptions if another exception A is 
running and stuff them in a bag in the A exception. This is kind 
of dangerous since you hide potentially serious exceptions this 
way and it is not what I think of as exception chaining. To me 
exception chaining is preserve the exception chain on re-throws 
(like preserving the call stack).

So yep, ketmar, you are right. You should probably not be able to 
throw in finally without catching it, and you should be able to 
do a catch all without wrapping it up in a function. The 
alternatives such as the mechanics described in the language 
specs will lead to unreliable exception handling and poor 
recovery strategies IMO.


More information about the Digitalmars-d mailing list