Re:Current hardware trends make C++ exceptions harder to jus...
by olvy0 on Tuesday February 22, 2022 @04:22PM
(#30434022)
Totally agree, I do the same, up to and including having a chat with a coworker who wrote code like that. I just did that last week, in fact.
Code that uses exceptions like this is a code smell, especially when performance is important. Using exceptions as control flow instead of if/loops is not a good design, IMO.
Note that this is in C++. I consider this style of writing not idiomatic, despite the STL doing it. I use either error return codes or std::optional (itself having a set of problems but IMO better than exceptions).
I'm more willing to accept this kind of code in Java, where it's more or less idiomatic. Less so in C#, where the tendency in the last 15 years has been to use the Try__ method instead of throwing exceptions.
I only use exceptions for cleanly unwinding the stack when an unrecoverable error occurs. I design and implement my code so that is rare.