Catching Errors

Jon Degenhardt via Digitalmars-d digitalmars-d at puremagic.com
Thu Jan 19 19:05:43 PST 2017


On Friday, 20 January 2017 at 02:11:41 UTC, Adam D. Ruppe wrote:
> On Friday, 20 January 2017 at 01:24:18 UTC, Jon Degenhardt 
> wrote:
>> Is there a place in the docs that describe the difference 
>> between errors and exceptions? As to the particular example, 
>> why is it unsafe to recover from attempting to access memory 
>> past the end of the array, as long as the access was prevented?
>
> It is just that Errors are not necessarily *thrown*. The 
> implementation is allowed to immediately abort on them too - 
> your catch has no guarantee to actually run, whereas with 
> Exceptions, they are.

Thanks, that's helpful. I hadn't seen it before, but the 
documentation for Object.Error and Object.Exception is clear on 
the distinction (https://dlang.org/phobos/object.html#.Error). 
There the intent is clear that Object.Error is for "unrecoverable 
runtime errors", and "not safe to catch and handle".

An aside - The documentation I had read, in the Error Handling 
chapter of the Language Reference, 
https://dlang.org/spec/errors.html, is less crisp about this 
distinction than the documentation for Object.Error. Perhaps an 
opportunity to improve this part of the documentation.

--Jon


More information about the Digitalmars-d mailing list