Anonymous user
Exceptions/Catch an exception thrown in a nested call: Difference between revisions
Exceptions/Catch an exception thrown in a nested call (view source)
Revision as of 11:52, 9 January 2011
, 13 years ago→{{header|D}}
m (→{{header|PL/I}}: It's incomplete rather than incorrect.) |
|||
Line 286:
=={{header|D}}==
First exception will be caught and message will be displayed, second will be caught by default exception handler.
<lang D>import std.stdio: writeln;
class U0 : Exception {
}
class U1 : Exception {
}
void foo() {▼
foreach (i; 0 .. 2) {
▲class U0 : Exception { this() { super("U0 error message"); } }
▲class U1 : Exception { this() { super("U1 error message"); } }
▲void foo()
{ ▼
try {
bar(i);
} catch(U0 e) {
}
}
Line 309 ⟶ 307:
void bar(int i) { baz(i); }
void baz(int i) {
if (!i)
throw new U1;
}
void main() {
foo();
}</lang>
Result:
Exception U0 caught</pre>
▲test.U1: U1 error message
=={{header|Eiffel}}==
|