|
Boost : |
Subject: Re: [boost] [exception] uncaught_exception_count, scope(failure), scope(success)
From: Evgeny Panasyuk (evgeny.panasyuk_at_[hidden])
Date: 2013-02-05 16:23:54
06.02.2013 0:40, Emil Dotchevski:
> I'm not an expert on D but Google tells me that it doesn't support
> automatic deterministic termination.
Could you please describe what do you mean?
> So, if you have a file or a
> handle open, you need scope(exit) to close it. It also means that the
> programmer must keep track of all non-memory resources and dispose
> them "manually" like a C programmer.
> In C++, RAII makes scope(exit) unnecessary,
While scope(exit) is some kind of ad-hoc replacement for RAII wrappers,
scope(failure) and scope(success) are not.
Nowadays scope(failure) and scope(success) are emulated in C++ via
ScopeGuard idiom.
For motivating examples check:
ScopeGuard:
http://www.drdobbs.com/cpp/generic-change-the-way-you-write-excepti/184403758#
scope(failure)/scope(success):
http://channel9.msdn.com/Events/Lang-NEXT/Lang-NEXT-2012/Three-Unlikely-Successful-Features-of-D
,
http://channel9.msdn.com/Shows/Going+Deep/C-and-Beyond-2012-Andrei-Alexandrescu-Systematic-Error-Handling-in-C
(ScopeGuard11 part)
> and catch(...) is the same as scope(failure).
Compare:
scope(failure)
{
rollback1();
};
do1();
scope(failure)
{
rollback2();
};
do2();
scope(failure)
{
rollback3();
};
do3();
with
try
{
do1();
try
{
do2();
try
{
do3();
}
catch(...)
{
rollback3();
throw;
}
}
catch(...)
{
rollback2();
throw;
}
}
catch(...)
{
rollback1();
throw;
}
-- Evgeny Panasyuk
Boost list run by bdawes at acm.org, gregod at cs.rpi.edu, cpdaniel at pacbell.net, john at johnmaddock.co.uk