On 30/05/2022 02:10, Robert Ramey wrote:
On 5/28/22 3:39 PM, Andrzej Krzemienski wrote:
try {
lib::function(); } catch(lib::exception const&) { // handle failure }
Could you explain what's wrong with the above code?
I believe the point was that if exceptions are always caught immediately then it smacks of the "exceptions as control flow" anti-pattern, and a non-throwing form of the library function ought to be available/used instead. Essentially, the exception is being used as an alternative return value rather than as an actual exception. It's from the school of thought that exceptions should be "truly exceptional" -- i.e. any condition that might theoretically raise an exception can be explicitly checked in advance by a non-throwing method, such that a well-written program operating in a reasonable environment (e.g. not running out of heap or being actively attacked) should never throw nor catch any exceptions at all -- if it happens, it's a programmer error and should probably crash the app entirely. I don't entirely agree with that sentiment (particularly the last part), but I do agree that you should be able to turn on first-chance exceptions in your debugger and *not* have it breakpoint every second.