Cannot catch exception in debug mode

frame frame86 at live.com
Thu Aug 12 01:53:12 UTC 2021


Is this a known DMD bug or feature?


```d
void f(T)(int num)
{
     writefln("recognized %d as %s", num, T.stringof);
}

void main()
{
     try
     {
         throw new Exception("");
     }
     catch (Exception)
     {
         f!Exception(1);
     }
     catch (Throwable)
     {
         f!Throwable(1);
     }

     debug
     {
         try
         {
             throw new Exception("");
         }
         catch (Exception)
         {
             f!Exception(2);
         }
         catch (Throwable)
         {
             f!Throwable(2);
         }
     }
}

// prints
// recognized 1 as Exception
// recognized 2 as Throwable
```


More information about the Digitalmars-d-learn mailing list