Jump to content

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

Added 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>
 
Anonymous user
Cookies help us deliver our services. By using our services, you agree to our use of cookies.