[Issue 11574] Improper behavior of scope(failure)

d-bugmail at puremagic.com d-bugmail at puremagic.com
Mon Nov 25 00:03:13 PST 2013


https://d.puremagic.com/issues/show_bug.cgi?id=11574


monarchdodra at gmail.com changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
                 CC|                            |monarchdodra at gmail.com


--- Comment #3 from monarchdodra at gmail.com 2013-11-25 00:03:10 PST ---
> Shows how scope(failure) return's can prevent proper exception bubbling.

"scope(failure)" doesn't return. It lives "inside" the function it is declared
in. It "holds" a return statement. It "rethrows" only once at the end of its
block, but you are explicitly allowed to place a control statement inside the
scope to *not* rethrow. An example case would be:

//----
import std.stdio;

void main()
{
    foreach(i ; 0 .. 10)
    {
        scope(failure)
            continue; //Ignore exception and power through

        writeln(i);
        throw new Exception("");
    }
    writeln("done!");
}
//----

Another example could be an "Exception to return code" case:

//----
HRESULT foo() nothrow
{
    scope(failure) return E_FAIL;

    code_that_might_throw_here();
}
//----

So I think the behavior is correct. Maybe just not intuitive at first, or not
correctly documented.

-- 
Configure issuemail: https://d.puremagic.com/issues/userprefs.cgi?tab=email
------- You are receiving this mail because: -------


More information about the Digitalmars-d-bugs mailing list