Why exceptions for error handling is so important

Dicebot via Digitalmars-d digitalmars-d at puremagic.com
Mon Jan 12 12:36:44 PST 2015


On Monday, 12 January 2015 at 20:07:17 UTC, deadalnix wrote:
> On Sunday, 11 January 2015 at 13:06:27 UTC, Dicebot wrote:
>> What is your opinion of approach advertised by various 
>> functional languages and now also Rust? Where you return error 
>> code packed with actual data and can't access data without 
>> visiting error code too, compiler simply won't allow it.
>
> Rust has an approach very similar to exception, but they do not 
> unwind and trash the whole task instead. Under the hood, it is 
> exception, but tend to be faster as you don't go through the 
> landing pad/personality function dance, but do not 
> fundamentally differ.
>
> The second approach is to pack the result in some kind of 
> object that require checking (but you often don't have anything 
> meaningful to do on failure where you need to check) or 
> propagate the wrapper, à la maybe monad, and get rid of the 
> wrapper where you know what to do on error.
>
> These approach tend to be faster while keeping safety, but 
> requiring more work from the dev. They make sense if the error 
> is common, but are not pulling their weight for very rare 
> failure scenarios like disc running out of space.

Exceptions in Rust are more like Errors in D (but they terminate 
tasks, not the process!), Result wrapper seems to be standard 
approach for tasks D uses exceptions for, thus my original 
question.


More information about the Digitalmars-d mailing list