Boost logo

Boost :

From: David Abrahams (david.abrahams_at_[hidden])
Date: 2002-01-18 18:22:06


I apologize; this is my fault. The documentation wasn't updated after I made
that change. The change was made in order to accomodate compilers which have
problems dealing with a particular EH idiom:

    void my_function()
        try

            something_that_might_throw();
        }
        catch(...) {
            handle_exception();
        }
    }

    void handle_exception()
    {
        try { throw; } // rethrow the currently-active exception
        catch(e1)
        {
            ...
        }
        catch(e2)
            ...
        catch(...)
        {
            // unknown error
            ...
        }
    }

Many compilers didn't handle the line labelled "rethrow..." well. The new
model is that handle_exception gets passed a 0-argument function object
which does what you want: simply,

    handle_exception(something_that_might_throw);

The problem with this is that you might need to pass arguments to
something_that_might_throw. For that, just use the Boost.Bind library:

    handle_exception(boost::bind<void>(something_that_might_throw, arg1,
arg2));

which creates a 0-argument function object that passes arg1 and arg2 to
something_that_might_throw.

HTH,
Dave

----- Original Message -----
From: "jfo60540" <jfo60540_at_[hidden]>
To: <boost_at_[hidden]>
Sent: Friday, January 18, 2002 6:08 PM
Subject: [boost] boost.python exception handling

> Hi -
>
> I am using boost.python from boost 1_26 with g++ 3.02 and python 2.2
> under solaris 2.7. I have had quite a bit of success wrapping numerous
> classes, but I cannot figure how to handle ++ exceptions. The simple
> example in the documentation i.e.
>
> catch(...)
> {
> python::handle_exception(); // Deal with the exception for Python
> }
>
> does not compile, apparently because handle_exception() expects a void
> (*)() argument. Can someone please give me a short example to
> demonstrate the correct way of handling c++ exceptions with
> boost.python ?
>
> Thanks !
>
>
> Info: http://www.boost.org Send unsubscribe requests to:
<mailto:boost-unsubscribe_at_[hidden]>
>
> Your use of Yahoo! Groups is subject to http://docs.yahoo.com/info/terms/
>
>


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