When i am inheriting from std::exception in order to define my own exception type, i need to override the what() method, which has the following signature:
virtual const char* what() const throw();
This definitely looks strange to me, like if there were two method names in the signature. Is this some very specific syntax, like with pure virtual methods, e.g.:
virtual int method() const = 0;
or is this a feature, that could somehow be used in another context, too? And if so, for what could it be used?
It is called
exception specifications. Thethrow()doesn’t allow any exception to be thrown from inside this methodthrow(int)would only allow exceptions of typeintto be thrown.Exception specifications will be dropped in C++0x. This gives a very good explanation of the reasons.