Alternatives to exceptions for error handling

Max Haughton maxhaton at gmail.com
Tue Jan 5 18:18:27 UTC 2021


On Tuesday, 5 January 2021 at 17:59:41 UTC, sighoya wrote:
> On Monday, 30 November 2020 at 11:02:29 UTC, Ali Çehreli wrote:
>>That's all... Exceptions are the simplest error management.
>
> +1.
>
> Please leave exceptions as default and optionally introduce 
> other ways for specific kind of work.
>
>>For me, their only problem is the performance impact, which I 
>>haven't even measured. :)
>
> But exactly this is the way exceptions are defined, they should 
> be exceptions, i.e. they should rarely pop up. With this in 
> mind, code execution with exceptions is as fast as with no 
> error handling at all, which isn't the case with Rust's error 
> handling.
>
> What you may want instead are signals which implicitly pass a 
> pointer of possible continuations down the stack or maybe by 
> just overwriting a global continuation variable to quickly jump 
> in. They are interesting for cases where you expect an event to 
> happen more than not.
>
> Disadvantages are however:
>
> - a small footprint registering landing pads (catch 
> regions/continuations)
> - don't fit that well with reference counted objects

You'd have to seriously measure the overhead - exceptions *are* 
nominally zero-cost but compilers don't like optimising when they 
can be thrown because it massively complicates the control flow 
analysis. That's partly what walter was referring to in the first 
place.

At very least exceptions should not be the default for (say) 
parser errors because they aren't exceptional.


More information about the Digitalmars-d mailing list