www.digitalmars.com         C & C++   DMDScript  

digitalmars.D.learn - Cannot catch exception in debug mode

reply frame <frame86 live.com> writes:
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
```
Aug 11 2021
parent reply Adam D Ruppe <destructionator gmail.com> writes:
On Thursday, 12 August 2021 at 01:53:12 UTC, frame wrote:
 Is this a known DMD bug or feature?
Huh that is weird, it works correctly in gdc but i can reproduce in dmd and ldc. And removing the debug keyword makes it work. Certainly smells like a regression bug to me.
Aug 11 2021
parent reply kinke <noone nowhere.com> writes:
On Thursday, 12 August 2021 at 02:03:39 UTC, Adam D Ruppe wrote:
 On Thursday, 12 August 2021 at 01:53:12 UTC, frame wrote:
 Is this a known DMD bug or feature?
Huh that is weird, it works correctly in gdc but i can reproduce in dmd and ldc. And removing the debug keyword makes it work. Certainly smells like a regression bug to me.
Yep, apparently a v2.094 frontend regression (the `catch(Exception)` in the debug block is removed from the AST): https://run.dlang.io/is/nPRiT7 frame: Please file an issue.
Aug 11 2021
parent frame <frame86 live.com> writes:
On Thursday, 12 August 2021 at 03:46:00 UTC, kinke wrote:

  frame: Please file an issue.
https://issues.dlang.org/show_bug.cgi?id=22205
Aug 12 2021