Free Trial

Safari Books Online is a digital library providing on-demand subscription access to thousands of learning resources.


  • Create BookmarkCreate Bookmark
  • Create Note or TagCreate Note or Tag
  • DownloadDownload
  • PrintPrint

Exceptions

If 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

					  


  

You are currently reading a PREVIEW of this book.

                                                                                        

Get instant access to over
$1 million worth of books and videos.

  

Start a Free Trial