You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
The compiler will still invisibly add specification noexcept to your destructor. And this means that the moment your destructor throws an exception, std::terminate will be called, even if there was no double-exception situation. If you are really determined to allow your destructors to throw, you will have to specify this explicitly; you have three options:
Explicitly specify your destructor as noexcept(false),
Inherit your class from another one that already specifies its destructor as noexcept(false).
Put a non-static data member in your class that already specifies its destructor as noexcept(false).
The text was updated successfully, but these errors were encountered:
MenaceSan
changed the title
Dont allow exceptions to escape destructors
Dont allow exceptions to escape destructors. (App Terminates!)
Feb 6, 2023
This can/will cause the application to terminate !
~work_finished_on_block_exit()
{
io_context_->work_finished();
}
work_finished(); will call win_iocp_io_context::stop() which can throw boost::system::error_code
This causes the whole application to terminate even if its inside a try /catch block.
Please add a try / catch to prevent this from escaping the destructor. (or add noexcept(false))
https://stackoverflow.com/questions/130117/if-you-shouldnt-throw-exceptions-in-a-destructor-how-do-you-handle-errors-in-i
Very bad effect on the application.
Simple fix:
~work_finished_on_block_exit() try {
io_context_->work_finished();
} catch (...) {}
or better fix:
just add noexcept(false) to the destructor. e.g.:
~work_finished_on_block_exit() noexcept(false)
from: https://akrzemi1.wordpress.com/2011/09/21/destructors-that-throw/
Explicitly specify your destructor as noexcept(false),
Inherit your class from another one that already specifies its destructor as noexcept(false).
Put a non-static data member in your class that already specifies its destructor as noexcept(false).
The text was updated successfully, but these errors were encountered: