4969 – nothrow check can't handle multiple catches

D issues are now tracked on GitHub. This Bugzilla instance remains as a read-only archive.
Issue 4969 - nothrow check can't handle multiple catches
Summary: nothrow check can't handle multiple catches
Status: RESOLVED FIXED
Alias: None
Product: D
Classification: Unclassified
Component: dmd (show other issues)
Version: D2
Hardware: Other Linux
: P2 normal
Assignee: No Owner
URL:
Keywords: patch, rejects-valid
Depends on:
Blocks:
Reported: 2010年10月01日 20:55 UTC by Jonathan M Davis
Modified: 2011年06月20日 16:34 UTC (History)
3 users (show)

See Also:


Attachments
Add an attachment (proposed patch, testcase, etc.)

Note You need to log in before you can comment on or make changes to this issue.
Description Jonathan M Davis 2010年10月01日 20:55:33 UTC
This code should compile:
class MyException : Exception
{
 this()
 {
 super("An exception!");
 }
}
void throwAway()
{
 throw new MyException;
}
void cantthrow() nothrow
{
 try
 throwAway();
 catch(MyException me)
 assert(0);
 catch(Exception e)
 assert(0);
}
void main()
{
}
It doesn't. Instead, you get this error:
d.d(14): Error: function d.cantthrow 'cantthrow' is nothrow yet may throw
If you remove catch(MyException e) and its body, then the program compiles. Given that the catch block that catches MyException cannot throw an exception of its own and that the catch block following it catches Exception (and therefore will catch all exceptions) and cannot throw an exception, the compiler should be able to clearly determine that no exception can escape cantthrow, but apparently, it can't.
Comment 1 kennytm 2011年06月19日 09:34:14 UTC
DMD pull #145.
https://github.com/D-Programming-Language/dmd/pull/145 


AltStyle によって変換されたページ (->オリジナル) /