Anonymous user
Exceptions/Catch an exception thrown in a nested call: Difference between revisions
Exceptions/Catch an exception thrown in a nested call (view source)
Revision as of 11:31, 17 September 2013
, 10 years agoAdded Erlang
(added Nemerle) |
(Added Erlang) |
||
Line 754:
Caught a U0 with message: 'This is the U0 exception'
This is the U1 exception
</pre>
=={{header|Erlang}}==
<lang Erlang>
-module( exceptions_catch ).
-export( [task/0] ).
task() -> [foo(X) || X<- lists:seq(1, 2)].
baz( 1 ) -> erlang:throw( u0 );
baz( 2 ) -> erlang:throw( u1 ).
foo( N ) ->
try
baz( N )
catch
_:u0 -> io:fwrite( "Catched ~p~n", [u0] )
end.
</lang>
{{out}}
<pre>
76> exceptions_catch:task().
Catched u0
** exception throw: u1
in function exceptions_catch:baz/1 (src/exceptions_catch.erl, line 10)
in call from exceptions_catch:foo/1 (src/exceptions_catch.erl, line 14)
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>
|