tags:

views:

89

answers:

2

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?

A: 
virtual const char* what() const throw();

what() is a virtual constant method that returns pointer to const char and must not throw any exception. Not very strange method declaration :)

Messa
the throw() is a list of all the exception types `what` might throw. And since there's nothing in the list, it doesn't throw anything. Exception lists are generally considered horrible so rarely appear in the wild. And they're going away, so they will become even rarer.
Kate Gregory
+9  A: 

It is called exception specifications. The throw() doesn't allow any exception to be thrown from inside this method throw(int) would only allow exceptions of type int to be thrown.

Exception specifications will be dropped in C++0x. This gives a very good explanation of the reasons.

pmr
thanks, that is exactly what i wanted to know :) hard to find something on the net if you don't know what you're looking for.
padde
+1, for the explanation and the link
neuro