Boost logo

Boost :

From: Emil Dotchevski (emildotchevski_at_[hidden])
Date: 2006-07-08 04:16:56


> Why return a pointer? How about considering the use of a reference
> instead?

If you catch( foo & ), it is not guaranteed that it has an exception_info
sub-object. For one thing, you may be converting existing code to the
exception library, and there could be some throw foo() statements left
around.

But also, consider catching one of the standard exception types, for example
std::length_error. It could have been thrown by the standard library and in
that case it would not have exception_info sub-object; or, some other code
could throw failed<std::length_error>(), and then there would be an
exception_info sub-object.

So, get_exception_info returns a pointer because it is intended to be used
like this:

catch( my_error & x )
{
    if( exception_info * xi = get_exception_info(x) )
    {
        //use exception_info here
    }
    else
    {
        //handle the case of not having exception_info.
    }
}

--Emil


Boost list run by bdawes at acm.org, gregod at cs.rpi.edu, cpdaniel at pacbell.net, john at johnmaddock.co.uk