Exceptions/Catch an exception thrown in a nested call: Difference between revisions
Content added Content deleted
Line 51: | Line 51: | ||
=={{header|Aime}}== |
=={{header|Aime}}== |
||
<lang aime>void |
<lang aime>void |
||
baz(integer i |
baz(integer i) |
||
{ |
{ |
||
error(cat("U", itoa(i))); |
|||
error(exception); |
|||
} |
} |
||
void |
void |
||
bar(integer i |
bar(integer i) |
||
{ |
{ |
||
baz(i |
baz(i); |
||
} |
} |
||
Line 70: | Line 69: | ||
i = 0; |
i = 0; |
||
while (i < 2) { |
while (i < 2) { |
||
text e; |
|||
if (trap_d(e, bar, i)) { |
|||
o_form("Exception `~' thrown\n", e); |
o_form("Exception `~' thrown\n", e); |
||
if (e != "U0") { |
if (e != "U0") { |
||
Line 93: | Line 92: | ||
}</lang> |
}</lang> |
||
{{out}} |
{{out}} |
||
<pre> |
<pre>Exception `U0' thrown |
||
Exception `U0' thrown |
|||
aime: tmp/nce: 5: U1 |
|||
Exception `U1' thrown |
Exception `U1' thrown |
||
will not catch exception |
will not catch exception |
||
aime: |
aime: nec: 26: U1</pre> |
||
Exception U0 is caught, exception U1 is caught and re-thrown. Program execution is terminated as the U1 exception is not caught when thrown the second time. |
Exception U0 is caught, exception U1 is caught and re-thrown. Program execution is terminated as the U1 exception is not caught when thrown the second time. |
||