Boost logo

Boost :

Subject: Re: [boost] D-style scope guards?
From: John Bytheway (jbytheway+boost_at_[hidden])
Date: 2010-09-17 13:56:30


On 17/09/10 11:37, Yakov Galka wrote:
> Why don't you use std::uncaught_exception() instead of exception_thrown?
>
> Also in my opinion this is a cleaner solution:
> void foo()
> {
> BOOST_SCOPE_EXIT(empty capture list not supported yet)
> cout << "Returning from foo()" << endl;
> if(!std::uncaught_exception())
> cout << "foo(): No Errors occurred!" << endl;
> else
> cout << "foo(): Exception caught!" << endl;
> BOOST_SCOPE_EXIT_END
> // ...
> }

That won't work in general; std::uncaught_exception might return true
because of another pending exception that's going on 'outside' of foo()
(e.g. if foo() is called from a destructor).

For more details:
http://www.gotw.ca/gotw/047.htm

John Bytheway


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