[EMAIL PROTECTED] wrote:
*Type* info
*Title* class comphelper::ScopeGuard
*Posted by* [EMAIL PROTECTED]
*Affected* ...,
*Effective from* SRC680/m90
/*Summary*/
Introduction of a ScopeGuard class to execute a functor when leaving scope,
e.g. good for automatic cleanup.
/*Description*/
I have added a ScopeGuard class to comphelper which eases writing
exception-safe code. It perfectly embraces boost::bind generated
functors, e.g.
#include "comphelper/scopeguard.hxx"
using comphelper::ScopeGuard;
...
{
ScopeGuard guard( boost::bind( &MyClass::setWaitState, this, false
) );
setWaitState(true);
...
} // wait state will be reset to false leaving this scope
By default, the guard catches and ignores all exceptions being thrown
by the functor in its destructor (but OSL_ asserts them).
This is defensive behaviour, because exceptions being thrown in
destructors during stack unwinding will lead to terminate()!
Nevertheless, if you want to allow exceptions (for good reason), you
can switch this:
ScopeGuard guard( <functor>, ScopeGuard::ALLOW_EXCEPTIONS );
*Would* there be good reason to do so?
-Stephan
BTW: The implementation uses Boost.Function (
http://www.boost.org/doc/html/function.html ) which is also available now.
---------------------------------------------------------------------
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]