D issues are now tracked on GitHub. This Bugzilla instance remains as a read-only archive.
Issue 20797 - Destructor marked as nothrow renders try-catch block useless
Summary: Destructor marked as nothrow renders try-catch block useless
Status: RESOLVED INVALID
Alias: None
Product: D
Classification: Unclassified
Component: dmd (show other issues)
Version: D2
Hardware: x86_64 Linux
: P1 enhancement
Assignee: No Owner
URL:
Keywords:
Depends on:
Blocks:
 
Reported: 2020-05-05 04:04 UTC by RazvanN
Modified: 2020-05-05 09:40 UTC (History)
1 user (show)

See Also:


Attachments

Note You need to log in before you can comment on or make changes to this issue.
Description RazvanN 2020-05-05 04:04:13 UTC
struct 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

Expected result: code does not throw exception.
Comment 1 Nicholas Wilson 2020-05-05 04:35:37 UTC
Doesn't throw or doesn't catch the crown exception? I think it should throw and catch.
Comment 2 RazvanN 2020-05-05 08:43:13 UTC
(In reply to Nicholas Wilson from comment #1)
> Doesn't throw or doesn't catch the crown exception? I think it should throw
> and catch.

Yes, I meant, that the expected result is that code exits gracefully by throwing and catching exactly 1 exception.
Comment 3 RazvanN 2020-05-05 09:40:24 UTC
Closing this. I was on a branch where I did some modifications to some other code. On git master it does this issue does not manifest.