If your goal is to throw an exception so that you do not throw a universal exception ( cpp: S112 ), you might just want to provide the exception you inherited from ( C ++ 11 ) using the using declaration.
Here is a minimal example for this:
#include <exception> #include <iostream> struct myException : std::exception { using std::exception::exception; }; int main(int, char*[]) { try { throw myException{ "Something Happened" }; } catch (myException &e) { std::cout << e.what() << std::endl; } return{ 0 }; }
As Kilian points out in the comment section, the example depends on the particular implementation of std :: exception, which offers more constructors than mentioned here .
To avoid this, you can use any of the convenient classes predefined in the <stdexcept> header. Check out these Exception Categories for inspiration.
Johannes Jul 12 '18 at 20:18 2018-07-12 20:18
source share