I\'m trying to create a custom exception that derives from std::exception
and overrides what()
. At first, I wrote it like this:
class U
use BOOST_NOEXCEPT
in
The boost config library was designed for compatibility issues like this. According to the doc:
If
BOOST_NO_CXX11_NOEXCEPT
is defined (i.e. C++03 compliant compilers) these macros are defined as:#define BOOST_NOEXCEPT #define BOOST_NOEXCEPT_OR_NOTHROW throw() #define BOOST_NOEXCEPT_IF(Predicate) #define BOOST_NOEXCEPT_EXPR(Expression) false
If
BOOST_NO_CXX11_NOEXCEPT
is not defined (i.e. C++11 compliant compilers) they are defined as:#define BOOST_NOEXCEPT noexcept #define BOOST_NOEXCEPT_OR_NOTHROW noexcept #define BOOST_NOEXCEPT_IF(Predicate) noexcept((Predicate)) #define BOOST_NOEXCEPT_EXPR(Expression) noexcept((Expression))
Many of the other answers here have a similar implementation but this library is cleaner, better tested, and will do the right thing when your compiler is upgraded. I recommend looking at the boost config library in general for other features, especially in this time of language flux and varying levels of support among compilers.