Bug 4969 – nothrow check can't handle multiple catches

Status
RESOLVED
Resolution
FIXED
Severity
normal
Priority
P2
Component
dmd
Product
D
Version
D2
Platform
Other
OS
Linux
Creation time
2010-10-01T20:55:00Z
Last change time
2011-06-20T16:34:00Z
Keywords
patch, rejects-valid
Assigned to
nobody
Creator
issues.dlang

Comments

Comment #0 by issues.dlang — 2010-10-01T20:55:33Z
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 by kennytm — 2011-06-19T09:34:14Z
Comment #2 by bugzilla — 2011-06-20T16:34:00Z