Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Dont allow exceptions to escape destructors. (App Terminates!) #1216

Closed
MenaceSan opened this issue Jan 31, 2023 · 1 comment
Closed

Dont allow exceptions to escape destructors. (App Terminates!) #1216

MenaceSan opened this issue Jan 31, 2023 · 1 comment

Comments

@MenaceSan
Copy link

MenaceSan commented Jan 31, 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/

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).

@MenaceSan MenaceSan changed the title Dont allow exceptions to escape destructors Dont allow exceptions to escape destructors. (App Terminates!) Feb 6, 2023
@MenaceSan
Copy link
Author

looks like this is now addressed in a33370c [a33370c]. Thanks!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant