Exceptions/Catch an exception thrown in a nested call: Difference between revisions

Add Factor example
(Add Factor example)
Line 1,014:
in call from exceptions_catch:'-task/0-lc$^0/1-0-'/1 (src/exceptions_catch.erl, line 5)
in call from exceptions_catch:'-task/0-lc$^0/1-0-'/1 (src/exceptions_catch.erl, line 5)
</pre>
 
=={{header|Factor}}==
<lang factor>USING: combinators.extras continuations eval formatting kernel ;
IN: rosetta-code.nested-exceptions
 
ERROR: U0 ;
ERROR: U1 ;
 
: baz ( -- )
"IN: rosetta-code.nested-exceptions : baz ( -- ) U1 ;"
( -- ) eval U0 ;
 
: bar ( -- ) baz ;
 
: foo ( -- )
[
[ bar ] [
dup T{ U0 } =
[ "%u recovered\n" printf ] [ rethrow ] if
] recover
] twice ;
 
foo</lang>
{{out}}
<pre>
T{ U0 } recovered
U1
 
(U) Quotation: [ c-to-factor => ]
Word: c-to-factor
(U) Quotation: [ [ (get-catchstack) push ] dip call => (get-catchstack) pop* ]
(O) Word: command-line-startup
(O) Word: run-script
(O) Word: foo
(O) Word: baz
(O) Word: U1
(O) Method: M\ object throw
(U) Quotation: [
OBJ-CURRENT-THREAD special-object error-thread set-global
current-continuation => error-continuation set-global
[ original-error set-global ] [ rethrow ] bi
]
</pre>
 
1,808

edits