Bug 7049 – Multiple scope(failure) blocks don't work in @safe code
Status
RESOLVED
Resolution
WORKSFORME
Severity
normal
Priority
P2
Component
dmd
Product
D
Version
D2
Platform
Other
OS
All
Creation time
2011-12-02T08:49:00Z
Last change time
2013-08-20T20:47:03Z
Keywords
rejects-valid
Assigned to
nobody
Creator
code
Comments
Comment #0 by code — 2011-12-02T08:49:46Z
---
@safe void foo() {
scope (failure) {}
scope (failure) {}
}
---
DMD 2.057 Git (887dda0ba) gives:
---
Error: can only catch class objects derived from Exception in @safe code, not 'object.Throwable'
Error: undefined identifier __o1300
---
The reason for this are the artificial try/catch blocks generated around statement.c:530.
Comment #1 by issues.dlang — 2011-12-02T08:54:17Z
That's odd. That would imply that the try-catch blocks generated by scope(failure) are using catch(Throwable) instead of catch(Exception), but scope statements are supposed to be skipped when Errors are thrown, so there's no reason for them be catching Throwable instead of Exception.
Comment #2 by hsteoh — 2013-08-19T20:15:35Z
Seems to be fixed in git HEAD. To prove that it actually works, I expanded the test code a bit:
----------
import std.stdio;
int count = 0;
@safe void foo() {
scope (failure) { count++; }
scope (failure) { count++; }
throw new Exception("failed");
}
void main() {
try {
foo();
} catch(Exception e) {
}
writeln(count);
}
----------
Output:
2
Comment #3 by andrej.mitrovich — 2013-08-19T20:20:06Z
It would be great to add these test-cases of worksforme bugs to the test-suite, if they're not already there.