www.digitalmars.com         C & C++   DMDScript  

digitalmars.D.bugs - [Issue 15652] New: Alias this exceptions cannot be caught, but


          Issue ID: 15652
           Summary: Alias this exceptions cannot be caught, but shadow
           Product: D
           Version: D2
          Hardware: All
                OS: All
            Status: NEW
          Severity: normal
          Priority: P1
         Component: dmd
          Assignee: nobody puremagic.com
          Reporter: bugzilla kyllingen.net

Say we have two exception classes, Foo and Bar, where Bar is a subtype of Foo
via "alias this":

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

    class Bar : Exception
            foo = new Foo;
        Foo foo;
        alias foo this;

Now, we try to throw a Bar and catch it as a Foo:

    try { throw new Bar; }
    catch (Foo) { }

This compiles and runs, but does not work as expected; the exception is not
caught.  But then, that ought to mean that the following code is perfectly

    try { throw new Bar; }
    catch (Foo) { /* ... */ }  // A
    catch (Bar) { /* ... */ }  // B

However, this doesn't even compile.

    Error: catch at [line A] hides catch at [line B]

I don't know what is supposed to be the correct behaviour here, but one of
these cases should work.

Feb 07 2016