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?
Microsoft Visual C++'s std::exception(const char*)
constructor is non-standard. While in the C++ Standard Library, std::exception has a const char* what() const
method, it provides no way of specifying a string except by overriding.
You should rewrite your code to use std::runtime_error
or 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.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With