[erlang-questions] wanted: example of try/catch

Richard Carlsson richardc@REDACTED
Fri Dec 8 16:25:40 CET 2006


Bengt Kleberg wrote:
>  it has lead me to
> belive that this super simple example should produce 'kalle' in the 
> erlang shell:
> 
> try false = true catch Error -> kalle end.
> 
> it does not. i get:
> ** exited: {{badmatch,true},[{erl_eval,expr,3}]} **

If you leave out the 'Class:' part of the exception pattern,
it defaults to 'throw:'. Here's how it works:

1> try false = true catch Class:Term -> {got,Class,Term} end.
{got,error,{badmatch,true}}
2> try throw(fred) catch Term -> kalle end.
kalle

     /Richard




More information about the erlang-questions mailing list