digitalmars.D.learn - Bug?
- RazvanN (28/28) May 04 2020 truct K
- Simen =?UTF-8?B?S2rDpnLDpXM=?= (10/38) May 04 2020 Surely the above code, which silently discards the exception,
- RazvanN (3/14) May 05 2020 Ah sorry! I was on a branch were I had some other modifications.
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
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
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:Ah sorry! I was on a branch were I had some other modifications. Indeed in git master the issue does not manifest.[...]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 05 2020