Declaring exception specifications in class hierarchy : Exception « Exceptions « C++ Tutorial






#include <string>
#include <typeinfo>

class base {
public:
  virtual void f() throw();
  virtual void g(); // can throw anything
  virtual void h() throw(std::string);
};

class derived : public base {
public:
  virtual void f() throw();    // OK: same as base
  virtual void g() throw(int); // OK: subset of base
  //virtual void h() throw(int); // Error: int not in base
};

class more : public derived {
public:
  //virtual void f();            // Error: can throw anything
  virtual void g() throw();    // OK
};








6.3.Exception
6.3.1.Declaring exception specifications in class hierarchy
6.3.2.Handling Derived-Class Exceptions
6.3.3.Demonstrating stack unwinding