I have an exception class as follows:
#include <exception>
struct InvalidPathException : public std::exception
{
explicit InvalidPathException() {}
const char* what() const;
};
const char*
InvalidPathException::what() const {
return "Path is not valid";
}
When compiling under GCC 4.4 with -Wall -std=c++0x
error: looser throw specifier for 'virtual const char* InvalidPathException::what() const'
error: overriding 'virtual const char* std::exception::what() const throw ()'
Quite right, too, since I'm overriding std::exception
's what()
method that does indeed have a throw()
exception specifier. But as one will often be informed, we shouldn't use exception specifiers. And as I understand it, they are deprecated in C++11, but evidently not yet in GCC with -std=c++0x.
So I'd be interested in the best approach for now. In the code I'm developing I do care about performance and so worry about the oft-mentioned overhead of throw()
, but in reality is this overhead so severe? Am I right in thinking that I'd only suffer it when what()
is actually called, which would only be after such an exception is thrown (and likewise for the other methods inherited from std::exception that all have throw()
specifiers)?
Alternatively, is there a way to work around this error given by GCC?