Exception/Error division in D

Dmitry Olshansky dmitry.olsh at gmail.com
Wed May 30 01:49:15 PDT 2012


On 30.05.2012 12:33, deadalnix wrote:
> Le 24/05/2012 21:33, Sean Kelly a écrit :
>> On May 24, 2012, at 11:39 AM, Steven Schveighoffer wrote:
>>
>>> On Thu, 24 May 2012 06:27:12 -0400, Denis
>>> Shelomovskij<verylonglogin.reg at gmail.com> wrote:
>>>
>>>> Let's talk about an abstract situation without caring about breaking
>>>> existing code, current docs, implementation etc.
>>>>
>>>> Definitions:
>>>> * an Exception is something that tigers scope guards and executes
>>>> catch/finally blocks if thrown;
>>>> * an Error is something that doesn't do it.
>>>
>>> I'll give you a different definition:
>>>
>>> * an Exception is something that can be handled far away from the
>>> context of the error, because the system can safely unwind the stack.
>>> * an Error must be handled at the point the error occurred, or the
>>> program state is by definition invalid.
>>
>> This is a good point. OutOfMemory conditions aside, the only time I'd
>> want to recover from an Error condition was at the point the event
>> occurred, not somewhere up the stack.
>>
>
> Often, the point of Exception isn't to recover, but to fail as cleanly
> as possible. To do so, Error must trigger finally blocks and scope
> statement.

Yes, finally the voice of wisdom!

>
> They probably shouldn't be catchable in @safe code because of the
> possible invalid state of the program.
>
Interesting point btw.

> But still, often recovering isn't the point when it come to problem as
> bad as Errors.


-- 
Dmitry Olshansky


More information about the Digitalmars-d mailing list