Alternatives to exceptions for error handling

Gregor Mückl gregormueckl at gmx.de
Mon Nov 30 09:58:36 UTC 2020


On Sunday, 29 November 2020 at 23:20:13 UTC, Roman Kashitsyn 
wrote:
> On Sunday, 29 November 2020 at 19:52:27 UTC, Jacob Carlborg 
> wrote:
>> [..]
>
> Sure, it's not always possible to handle errors at the level 
> they arise, those need to be propagated.
> On the other hand, most of the time the caller has even less 
> clue on how to deal with the error: the further you go from the 
> point where error happened, the less likely it's going to be 
> handled in a meaningful way.
>

What kind of error conditions are you talking about that you 
consider handleable locally? Do you have concrete examples? I am 
asking because this is way outside the experiences I have made 
regarding error handling and I would like to understand your 
perspective.

Every serious application that I have ever worked on had to deal 
with errors in the context of larger operations. There were 
essentially no locally handleable errors. So every error has to 
go up a few layers until there is even enough context available 
for recovery. This happens for example when an change operation 
triggers a sanity check deep inside a complex data model. The 
failing check has no notion of whether the larger operation needs 
to be rolled back or whether this is expected by the controller 
and there is a fallback strategy.



More information about the Digitalmars-d mailing list