Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Alternative for std::exception(const char*) non-standard constructor

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?

like image 931
Ilya Avatar asked Jul 30 '12 22:07

Ilya


1 Answers

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.

like image 127
Ilya Avatar answered Nov 07 '22 05:11

Ilya