Why exceptions for error handling is so important

deadalnix via Digitalmars-d digitalmars-d at puremagic.com
Mon Jan 12 12:07:15 PST 2015


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.


More information about the Digitalmars-d mailing list