r/cpp • • Oct 05 '26

Measuring the Performance of Deterministic Exceptions

https://databasearchitects.blogspot.com/2026/09/measuring-performance-of-deterministic.html
49 Upvotes

16 comments sorted by

View all comments

1

u/UndefinedDefined Oct 12 '26

The only good exception is the one that never happens - that's my opinion.

I have seen so much code literally using exceptions for basic things, like FileNotFound - but these are not exceptions. I have even witnessed rewriting an error handling layer in a HTTP server to not use exceptions, because when it started throwing it reduced requests per second by two orders of magnitude, that essentialyl makes such code a candidate for DDoS attacks.

1

u/ABlockInTheChain Oct 22 '26

The idea that exceptions should be rare is a workaround for a performance reality rather than a universal philosophy that would hold in an alternate universe where exceptions had good performance in all case.

In that alternate universe where throwing exceptions had a predictable, reasonable runtime cost the focus would have been on the ergonomic tradeoffs: when does it improve readability and maintainability to handle errors immediately when they occur vs when is it better to write a happy path in a try block and defer error handling to the subsequent catch blocks or to the caller.

1

u/UndefinedDefined Oct 22 '26

Your alternative universe doesn't matter - we live in this one, and throwing is costly, which means you want to avoid it, which means that out of sudden you always need 2 error reporting mechanisms. I would rather not use exceptions than have to deal with both expectable errors and exceptions.