On Wednesday, 16 May 2012 at 05:39:08 UTC, Brad Roberts wrote:
On 5/15/2012 10:06 PM, Jonathan M Davis wrote:
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

And if otherStuff is marked all nothrow, then the exception parts are pulled out. It's pretty much the entire point of
having nothrow annotations.

Oooh, *that* I did not know. Very interesting, thanks for pointing that out!

Reply via email to