3 ms·
> Exceptions are an uber-goto, that can jump outside entire functions. Some people still like that, but very disciplined code bases (of which there are a lot in
by joshuamorton 7y ago
> Exceptions are an uber-goto, that can jump outside entire functions. Some people still like that, but very disciplined code bases (of which there are a lot in C++) tend to avoid them.
I've never heard discipline as a reason to be exceptionless, its always been performance related (specifically performance predictability).
- paulddraper 7y agoDiscipline can be mean strong performance too. In any case, exceptions are really only a performance problem if there are frequent. [1] Modern compilers and machines have near zero overhead for unthrown exceptions and 20x the overhead of an if-else. Chances are quite good that you have bigger performance problems than exceptions. [1] https://stackoverflow.com/questions/13835817/are-exceptions-in-c-really-slow https://stackoverflow.com/questions/13835817/are-exceptions-...
- joshuamorton 7y agoLike I said, performance predictability, not raw performance. if/else have predictable performance characteristics, while exceptions are fast usually and then occasionally very slow. The idea being that in an area where you'd like performance to be predictable, even in cases of unexpected results, Sum types or if/else give the same performance all the time.
- rumanator 7y ago> Like I said, performance predictability, not raw performance. Your argument makes absolutely no sense. Exceptions are used to handle exceptional events, the kind of stuff that would crash and shutdown your program. Exceptions are used to establish sanity checkpoints where any exceptional event can be caught and either recover from it or fail gracefully. Performance is measured on the happy path, and exceptions fall in the exact opposite of the happy path.
- joshuamorton 7y agoThere are cases where you want exceptional performance to also have predictable characteristics. I don't know why that doesn't make sense.
- IshKebab 7y agoI have. That's why languages always end up trying to add checked exceptions and then give up because it is too much of a pain in the arse. For C++ see https://en.cppreference.com/w/cpp/language/except_spec https://en.cppreference.com/w/cpp/language/except_spec and note that it has been removed from C++. Features are only very rarely removed from C++!