r/cpp • u/pavel_v • Apr 02 '26
What happens when a destructor throws
https://www.sandordargo.com/blog/2026/04/01/when-a-destructor-throws
104
Upvotes
r/cpp • u/pavel_v • Apr 02 '26
View all comments
Show parent comment
1
u/CornedBee Apr 03 '26
We have two assertion macros:
ASSERT_LOGIC throws a logic_error on failure. We use it to check our expectations that we think hold, and for preconditions of functions. But we will still keep the service up and handle other requests even if these fail. A failing assertion here means a bug in our program, but we trust our request isolation enough to not take down the whole program.
ASSERT_RUNTIME throws a runtime_error on failure. We use it to check for bad external input. A failing assertion here usually means a communicating service produces bad data for us, or database data is somehow corrupted, or user input was bad.
This seems perfectly in spirit with the
<stdexcept>exceptions. (<exception>doesn't contain the derived exceptions.) Now you could argue that the first case shouldn't be handled with exceptions, but as I said, we want to keep the service up. And also, if you argue this, you should also argue thatstd::logic_errorshouldn't exist.