I know that we can specify the compiler that a function is not throwing an exception by using noexcept specifier but noxecept functions can still throw exceptions . So, how to prevent destructor from throwing an exception ?
C++ Exception Handling – How to Ensure Destructors Cannot Throw Exceptions
cexception handling
Related Topic
- PHP Exceptions – Should You Throw Exceptions from a Constructor?
- C++ Performance – Using Error Codes in Libraries
- C++ – “Whole-team” C++ features
- C++ Exception Safety – Achieving Strong Exception Safety with Pass-by-Value Arguments
- Java – Why don’t constructor return bool to indicate its success or failure without having to throw an exception
Best Answer
If a function is declared as
nothrow
throws an exception anyway, that is a bug pure and simple.Given that, to ensure your destructors don't throw any exceptions, there are two paths:
nothrow
, they are documented not to throw, or they are implemented in a language without exceptions)try { } catch(...)
block.