info/SRC680/m90 : class comphelper::ScopeGuard
[email protected] Wed, 21 Sep 2005 13:06:54 +0200 (CEST)
| Newsgroups | gmane.comp.openoffice.announce.interface |
|---|---|
| Message-ID | <29304549.1127300814507.JavaMail.root@sd-web1> |
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 ); 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]