Thread overview | |||||
---|---|---|---|---|---|
|
May 05, 2020 Bug? | ||||
---|---|---|---|---|
| ||||
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 05, 2020 Re: Bug? | ||||
---|---|---|---|---|
| ||||
Posted in reply to RazvanN | 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 05, 2020 Re: Bug? | ||||
---|---|---|---|---|
| ||||
Posted in reply to Simen Kjærås | 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.
|
Copyright © 1999-2021 by the D Language Foundation