Feedback from the Gripes and Wishes Campaign

deadalnix deadalnix at gmail.com
Tue May 30 11:33:50 UTC 2023


On Tuesday, 30 May 2023 at 05:41:14 UTC, Richard (Rikki) Andrew 
Cattermole wrote:
> On 30/05/2023 9:18 AM, Ernesto Castellotti wrote:
>> Mainly because exceptions are often used for errors that 
>> aren't really exceptional", I often found myself having to 
>> handle exceptions (mostly in Java and C++) that really didn't 
>> give a damn and just abort the program.
>
> There are three categories that exceptions tend to fall into 
> from what I've been able to tell.
>
> 1. Errors, show stoppers (use assert)
> 2. Genuinely exceptional, can stop program if not handled (use 
> runtime exceptions)
> 3. Exceptional path ways, should not stop the program and needs 
> to be handled close to throw (use value type exceptions)
>
> A large portion of standard library stuff should really fall 
> into the third, not the first or second IMO. Whereas runtime + 
> threading should fall into first and second.

Exception are for one thing only: bailing out of some code 
because some problem occurred that cannot be handled locally. 
That's it, really.

The whole approach where one wonders if the error is recoverable 
or not or frequent or not and whatever is just the wrong way to 
think about it. The right way is the opposite way around: if you 
find yourself frequently throwing, then your API is likely wrong, 
because you find yourself not being able to handle something 
locally that happens all the time.


More information about the Digitalmars-d mailing list