exception syntax

In the example,

1
2
3
4
5
6
7
class myexception: public exception
{
  virtual const char* what() const throw()
  {
    return "My exception happened";
  }
} myex;


What is the reason for the two 'const' to exist in the declaration?
And why does it always need 'throw()' in order to successfully be a derived class from exception?
const char* is the return type (a pointer to char which can't be modified)
what() const means that what member function doesn't modify the class and it can be used with const objects
throw() because what would never throw exceptions (as myexception would be used to catch exception no of its members should throw exception or it will become very messy)
Topic archived. No new replies allowed.