scope(exit) without exception handling?
Jonathan M Davis
jmdavisProg at gmx.com
Tue May 15 22:06:28 PDT 2012
On Wednesday, May 16, 2012 05:54:04 Mehrdad wrote:
> I'm writing some (low-level) code with no exception handling
> available whatsoever... either the code runs, or it doesn't.
>
> 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?
scope(exit) stuff;
otherStuff;
is lowered to something like
try
{
otherStuff;
}
finally
{
stuff;
}
So, you can use scope(exit) if the above code is acceptable for whatever
you're doing. Otherwise, no, you can't.
Destructors should work regardless of what you're doing with exceptions
though, so I would expect RAII to work.
- Jonathan M Davis
More information about the Digitalmars-d
mailing list