Try/Cond

Richard Carlsson richardc@REDACTED
Tue Oct 21 21:05:07 CEST 2003


----- Original Message ----- 
From: "Sean Hinde" <sean.hinde@REDACTED>
To: "Richard Carlsson" <richardc@REDACTED>
Cc: "Erlang Questions" <erlang-questions@REDACTED>
Sent: Tuesday, October 21, 2003 8:50 PM
Subject: Re: Try/Cond


> So try is like (guessing):
> 
> try
>   func1(xx),
>   f2(yy)
> catch
>   {'EXIT', Reason} ->
>     {error, oops};
>   ok ->
>     ok
> end.
> 
> ?

The main points are 1) being able to definitely separate exceptions
from return values, and 2) being able to catch only those exceptions
one is interested in, letting everything else fall through. Something
like:

    try
      f(X)
    catch
      {throw, file_not_found} ->
          ...
    end

also, we want to be able to directly switch on the result in the
successful case. Something like this:

    try scan(FD) of
      foo -> ...;
      bar -> ...
    catch
      {throw, eof} ->
          ...
    end

        /Richard




More information about the erlang-questions mailing list