scope(exit) without exception handling?
Jonathan M Davis
jmdavisProg at gmx.com
Wed May 16 14:17:41 PDT 2012
On Wednesday, May 16, 2012 23:05:07 Timon Gehr wrote:
> On 05/16/2012 08:59 AM, Walter Bright wrote:
> > On 5/15/2012 8:54 PM, Mehrdad wrote:
> >> Is there any way for me to use scope(exit) (or perhaps a destructor,
> >> like RAII)
> >> to mean, "Execute this block of code for me when the block is exited,
> >> will ya?",
> >> *without* introducing dependencies on exception handling?
> >
> > Make sure the guarded code is 'nothrow', and it should work.
>
> Doesn't that imply that 'in'-contract checking might leave the program
> in an invalid state?
Well, according to Walter, there is no guarantee that _any_ cleanup will be
done when an Error is thrown (including AssertError), so yes, there's the
possibility that an in contract could leave the program in an invalid state if
it fails. However, with the current implementation, as I understand it, it
_is_ guaranteed that cleanup will be done for Errors. But if the try and
finally blocks are indeed removed, then that would seem to indicate that
there's a case where there _won't_ be any cleaup for Errors in spite of the
fact that Don (and and Dan?) tried to make sure that it _was_ guaranteed. But
if the cleanup doesn't happen, it would still be within what Walter considers
to be guarantee for Errors as far as the spec goes.
- Jonathan M Davis
More information about the Digitalmars-d
mailing list