www.digitalmars.com         C & C++   DMDScript  

digitalmars.D.learn - Bug?

reply RazvanN <razvan.nitu1305 gmail.com> writes:
truct K
{
     ~this() nothrow {}
}

void main()
{
     static class C
     {
         this(K, int) {}
     }

     static int foo(bool flag)
     {
         if (flag)
             throw new Exception("hello");
         return 1;
     }

     try
     {
         new C(K(), foo(true));
     }
     catch(Exception)
     {
     }
}

Result:

object.Exception test.d(18): hello

If the destructor of K is not marked nothrow the code does not 
throw an exception. Is this a bug or am I missing something?
May 04 2020
parent reply Simen =?UTF-8?B?S2rDpnLDpXM=?= <simen.kjaras gmail.com> writes:
On Tuesday, 5 May 2020 at 04:02:06 UTC, RazvanN wrote:
 truct K
 {
     ~this() nothrow {}
 }

 void main()
 {
     static class C
     {
         this(K, int) {}
     }

     static int foo(bool flag)
     {
         if (flag)
             throw new Exception("hello");
         return 1;
     }

     try
     {
         new C(K(), foo(true));
     }
     catch(Exception)
     {
     }
 }

 Result:

 object.Exception test.d(18): hello

 If the destructor of K is not marked nothrow the code does not 
 throw an exception. Is this a bug or am I missing something?
Surely the above code, which silently discards the exception, does not print "hello"? Regardless, I ran your code with writeln inside the catch(), and without the try-catch entirely, with and without nothrow on K's destructor. I am unable to replicate the issue on my computer with DMD 2.091.0, as well as on run.dlang.io. Is something missing in your code here? -- Simen
May 04 2020
parent RazvanN <razvan.nitu1305 gmail.com> writes:
On Tuesday, 5 May 2020 at 05:37:08 UTC, Simen Kjærås wrote:
 On Tuesday, 5 May 2020 at 04:02:06 UTC, RazvanN wrote:
 [...]
Surely the above code, which silently discards the exception, does not print "hello"? Regardless, I ran your code with writeln inside the catch(), and without the try-catch entirely, with and without nothrow on K's destructor. I am unable to replicate the issue on my computer with DMD 2.091.0, as well as on run.dlang.io. Is something missing in your code here? -- Simen
Ah sorry! I was on a branch were I had some other modifications. Indeed in git master the issue does not manifest.
May 05 2020