[Issue 15652] New: Alias this exceptions cannot be caught, but shadow others
    via Digitalmars-d-bugs 
    digitalmars-d-bugs at puremagic.com
       
    Sun Feb  7 12:54:58 PST 2016
    
    
  
https://issues.dlang.org/show_bug.cgi?id=15652
          Issue ID: 15652
           Summary: Alias this exceptions cannot be caught, but shadow
                    others
           Product: D
           Version: D2
          Hardware: All
                OS: All
            Status: NEW
          Severity: normal
          Priority: P1
         Component: dmd
          Assignee: nobody at puremagic.com
          Reporter: bugzilla at 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
    {
        this()
        {
            super("Bar");
            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
fine:
    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.
--
    
    
More information about the Digitalmars-d-bugs
mailing list