4 ms·
Converting an exception into a return. Which loses the "have to deal with it; cannot ignore it" property that made the exception valuable. "The key takeaway he
by ratboy666 7y ago
Converting an exception into a return. Which loses the "have to deal with it; cannot ignore it" property that made the exception valuable.
"The key takeaway here is that an exception cannot be ignored or forgotten; if we have an exception, it must be dealt with."
If converted to simple "C style" status returns -- it is only 5 times slower (11.5ns vs 57.5ns) -- and can be ignored and forgotten.
In the associated slide deck, boolean valid() must be used before value. In this case, this is just as unsafe as C return codes. A C++ exception is always considered an lvalue, meaning that union is initialized, but I am not sure what reading the other side results in (I don't think that this is allowed).
My take on this? Please use an exception if you mean an exception (for C++). If it is too slow (which I consider unlikely), please deal with it some other way (I would suggest a status return).
- patrec 7y ago> Converting an exception into a return. Which loses the "have to deal with it; cannot ignore it" property that made the exception valuable. [[nodiscard]] -Werror
- jcelerier 7y ago> "The key takeaway here is that an exception cannot be ignored or forgotten; if we have an exception, it must be dealt with." but a good way to deal with exceptions (in the very specific case of GUI desktop software, though that works also for server software that handles requests) is to just have a global catch handler at the top of your event loop which logs an error message / displays a message box to your user / does a preemptive backup save of the data in case something is deeply corrupted somewhere and then restarts the event loop.