Exceptions/Catch an exception thrown in a nested call: Difference between revisions
Content added Content deleted
(Added Quackery.) |
|||
Line 2,637: | Line 2,637: | ||
through the nested function calls together with the name of the |
through the nested function calls together with the name of the |
||
uncaught exception, (U1) to stderr, then quit the running program. |
uncaught exception, (U1) to stderr, then quit the running program. |
||
=={{header|Quackery}}== |
|||
<lang Quackery> [ this ] is U0 |
|||
[ this ] is U1 |
|||
[ 0 = iff U0 else U1 |
|||
message put bail ] is baz ( n --> ) |
|||
[ baz ] is bar ( n --> ) |
|||
[ 2 times |
|||
[ i^ |
|||
1 backup |
|||
bar |
|||
bailed if |
|||
[ message share |
|||
U0 oats iff |
|||
[ say "Exception U0 raised." cr |
|||
echostack |
|||
$ "Press enter to continue" |
|||
input drop |
|||
message release |
|||
drop ] |
|||
else [ drop bail ] ] ] ] is foo</lang> |
|||
{{out}} |
|||
Testing in the Quackery shell, first with trapping the exception U1, and then without trapping the exception U1 (this is bad practice). Before invoking <code>foo</code> we put some arbitrary data on the stack to show if and how it is affected. |
|||
<pre>/O> 111 222 333 |
|||
... |
|||
Stack: 111 222 333 |
|||
/O> 0 backup foo bailed if [ message take echo ] |
|||
... |
|||
Exception U0 raised. |
|||
Stack: 111 222 333 0 |
|||
Press enter to continue |
|||
U1 |
|||
Stack: 111 222 333 |
|||
/O> foo |
|||
... |
|||
Exception U0 raised. |
|||
Stack: 111 222 333 0 |
|||
Press enter to continue |
|||
Problem: Cannot remove an immovable item. |
|||
Quackery Stack: 111 222 333 |
|||
Return stack: {[...] 0} {quackery 1} {[...] 11} {shell 5} {quackery 1} {[...] 0} {foo 2} {times 6} |
|||
{[...] 10} {[...] 6} {[...] 7} {[...] 1} {bail 1} |
|||
/O> |
|||
Stack empty. |
|||
</pre> |
|||
=={{header|R}}== |
=={{header|R}}== |