[Issue 16177] New: Inner exception cannot be caught by specific type; becomes a collateral of the original exception

via Digitalmars-d-bugs digitalmars-d-bugs at puremagic.com
Thu Jun 16 15:27:03 PDT 2016


https://issues.dlang.org/show_bug.cgi?id=16177

          Issue ID: 16177
           Summary: Inner exception cannot be caught by specific type;
                    becomes a collateral of the original exception
           Product: D
           Version: D2
          Hardware: x86_64
                OS: Linux
            Status: NEW
          Severity: normal
          Priority: P1
         Component: dmd
          Assignee: nobody at puremagic.com
          Reporter: acehreli at yahoo.com

(This may be related to bug 15467.)

The inner exception cannot be caught by its own specific type. Because of that,
it becomes a collateral of the original exception.

/*
This BUG manifests itself on two conditions:

1) scope statement in main() must be 'exit' (change it to
   'failure' and there is no bug.)

2) bar() must catch by specific exception type Bar (alias
   TypeToCatch to Exception or Throwable in bar() and there is no
   bug.)
*/

class Foo : Exception { this() { super("Foo"); } }
class Bar : Exception { this() { super("Bar"); } }

void main() {
    /* First, a sanity check that bar() does indeed handle its
     * own exception. */
    bar();

    try {
        /* bar() will throw and handle it's own exception while a
         * Foo is in flight. */
        scope (exit) bar();

        /* This exception will be in flight while bar() throws
         * and handles its own exception. */
        throw new Foo();

    } catch (Foo e) {
        /* Since bar() has supposedly handled its own exception,
         * we expect no collateral exception here.  */

        assert(e.next is null);    // THIS ASSERT FAILS
    }
}

void bar() {
    bool caught = false;

    alias TypeToCatch = Bar;

    try {
        throw new Bar();

    } catch (TypeToCatch e) {
        caught = true;
    }

    assert(caught);
}

Ali

--


More information about the Digitalmars-d-bugs mailing list