Exception/Error division in D

Walter Bright newshound2 at digitalmars.com
Wed May 30 19:17:27 PDT 2012


On 5/30/2012 8:05 AM, Steven Schveighoffer wrote:
> I'd classify errors/exceptions into three categories:
>
> 1. corruption/segfault -- not recoverable under any reasonable circumstances.
> Special cases exist (such as a custom paging mechanism).
> 2. program invariant errors (i.e. assert errors) -- Recovery is not defined by
> the runtime, so you must do it manually. Any decision the runtime makes will be
> arbitrary, and could be wrong.
> 3. try/catch exceptions -- these are planned for and *expected* to occur because
> the program cannot control it's environment. e.g. EOF when none was expected.


A recoverable exception is NOT a logic bug in your program, which is why it is 
recoverable.

If there is recovery possible from a particular assert error, then you are using 
asserts incorrectly. Assert errors occur because your program has entered an 
unanticipated, invalid state. There's no such thing as knowing how to put it 
back into a valid state, because you don't know where it went wrong and how much 
is corrupted, etc.


More information about the Digitalmars-d mailing list