ExceptionsIf you have to override a base class virtual function that already has an exception specification (e.g., ahem, std::exception::what), and you don't have the ability to change the class to remove the exception specifications (or to convince the class's maintainer to remove them), you will have to write a compatible exception specification on your overriding function, and you should prefer to make it no less restrictive than the base version so as to minimize the frequency with which it might be violated: class Base {// … // in a class written by someone else virtual f() throw( X, Y, Z ); // the author used an exception specification, }; // and if you can't get him to remove it… class MyDerived : public Base {// … // …then in your own class your override virtual f() throw( X, Y, Z ); // must have a compatible (and preferably }; // the identical) exception specification [BoostLRG]'s experience is that a throws-nothing exception specification (i.e., throw()) on a non-inline function "may have some benefit with some compilers." Not a stunning endorsement from one of the most highly regarded and expertly designed C++ library projects in the world. |