Exceptions/Catch an exception thrown in a nested call: Difference between revisions
Content added Content deleted
(Added Io entry) |
|||
Line 1,376: | Line 1,376: | ||
Note: it may be possible to implement exceptions in Icon; however, |
Note: it may be possible to implement exceptions in Icon; however, |
||
it would require a major rework and would likely be inelegant. |
it would require a major rework and would likely be inelegant. |
||
=={{header|Io}}== |
|||
<lang Io>U0 := Exception clone |
|||
U1 := Exception clone |
|||
foo := method( |
|||
for(i,1,2, |
|||
try( |
|||
bar(i) |
|||
)catch( U0, |
|||
"foo caught U0" print |
|||
)pass |
|||
) |
|||
) |
|||
bar := method(n, |
|||
baz(n) |
|||
) |
|||
baz := method(n, |
|||
if(n == 1,U0,U1) raise("baz with n = #{n}" interpolate) |
|||
) |
|||
foo</lang> |
|||
{{out}} |
|||
<pre>foo caught U0 |
|||
U1: baz with n = 2 |
|||
--------- |
|||
U1 raise exceptions_catch_nested.io 34 |
|||
Object baz exceptions_catch_nested.io 31 |
|||
Object bar exceptions_catch_nested.io 24</pre> |
|||
The first line comes from when U0 was caught and the second from when U1 was raised and not caught. This is followed by a traceback with the most recent call first. |
|||
=={{header|J}}== |
=={{header|J}}== |