Why exceptions for error handling is so important

thedeemon via Digitalmars-d digitalmars-d at puremagic.com
Sun Jan 11 09:00:59 PST 2015


On Sunday, 11 January 2015 at 13:25:59 UTC, ketmar via 
Digitalmars-d wrote:
> On Sun, 11 Jan 2015 13:06:26 +0000
> Dicebot via Digitalmars-d <digitalmars-d at puremagic.com> 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.
> from my POV it trashes logic with error checking. hey, i don't 
> care if
> *each* `fwrite()` is successfull, i only care if all of them 
> are ok or
> at least one (any one) failed!

This is where monads and applicatives shine. You can describe the 
general logic (run 'till first error or collect and combine all 
errors or something else) in one place and then apply this way of 
error handling throughout with minimal code, and you can often 
change the error handling approach later just by changing a type, 
without editing actual function source code.


More information about the Digitalmars-d mailing list