Wednesday, October 13, 2010

Function Try Block

Given the following code:

    MyClass::MyClass()
    try
    : mSubobject(0)
    {
    }
    catch (...)
    {
    }


If mSubobject throws an exception during construction the MyClass constructor will rethrow the exception that mSubject threw.

This is a function try block. When something in the member initialization list throws an exception, the catch block can either rethrow the same exception, throw a different exception, or do nothing; in which case the runtime will rethrow the original exception. You can't suppress the exception.

Reference: More Exceptional C++ by Herb Sutter. Addison-Wesley, 2002., p. 120.

No comments:

Post a Comment