Alternatives to exceptions for error handling

sighoya sighoya at gmail.com
Tue Jan 5 18:35:09 UTC 2021


On Tuesday, 5 January 2021 at 18:18:27 UTC, Max Haughton wrote:
> 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.

Okay, this is new to me, could you elaborate a bit more please?

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

It depends, if you aren't interested in the content of the parsed 
file at all in case of a parser error, then exceptions might be 
the right choice. You throw them once, that's it.

If you are otherwise interested to gain anyway information from 
the file then errors in the return type make sense as they are 
now part of the considered information.

A good example are IDE compilers, where a parser error line- and 
column range is used for red marking the code. In addition, other 
places of parser errors have to be red marked after the same run.




More information about the Digitalmars-d mailing list