Up to C++03 destructors were generally allowed to throw arbitrary exceptions.
In C++11, however, all destructors without an explicit exception specification became noexcept
by default.
This can be overridden with noexcept(false)
but this code won't be accepted by pre-C++11 compilers.
One solution is to detect the need for noexcept(false)
by checking compiler-specific #define
s, but this still limits applicability of such code to the set of known compilers.
Is there any portable way to allow throwing arbitrary exceptions from destructors in both С++11 and C++03?