My Visual C++ code uses the std::exception constructor that accepts a string and I’m trying to port the code to Linux / G++. What exception class should I use?
My Visual C++ code uses the std::exception constructor that accepts a string and I’m
Share
Microsoft Visual C++’s
std::exception(const char*)constructor is non-standard. While in the C++ Standard Library, std::exception has aconst char* what() constmethod, it provides no way of specifying a string except by overriding.You should rewrite your code to use
std::runtime_erroror one of the other classes from<stdexcept>as an alternative. Existing code that catches std::exception does not need to be changed, of course, since std::runtime_error derives from it.