c++exception-specification

Is it possible to provide exceptions in C++ virtual(pure) class member?


If so how?

I know how to provide exception specifications for members such as

class SOMEClass
{
public:


   void method(void)  throw (SOMEException); 

   virtual void pure_method(void) = 0;
};

So that the method throws only SOMEException. If I want to ensure that sub-classes of SOMEClass throw SOMEException for pure_method, is it possible to add the exception specification?. Is this approach feasible or do I need to understand more on exceptions and abstract methods to find out why it can(not) be done?


Solution

  • Yes, a pure virtual member can have an exception specification.

    I recommend you to read this: http://www.gotw.ca/publications/mill22.htm before getting too much involved in exception specifications, though.