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, text &exception)
baz(integer i)
{
{
exception = cat("U", itoa(i));
error(cat("U", itoa(i)));
error(exception);
}
}


void
void
bar(integer i, text &exception)
bar(integer i)
{
{
baz(i, exception);
baz(i);
}
}


Line 70: Line 69:
i = 0;
i = 0;
while (i < 2) {
while (i < 2) {
text e;
text e;


if (trap(bar, i, 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>aime: tmp/nce: 5: U0
<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: tmp/nce: 29: U1</pre>
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.