Try/Cond
Sean Hinde
sean.hinde@REDACTED
Tue Oct 21 21:15:38 CEST 2003
On Tuesday, October 21, 2003, at 08:05 pm, Richard Carlsson wrote:
>
> ----- 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
So this is the same as:
case catch scan(Fd) of
foo -> ...;
bar -> ...;
{throw, eof} ->
....;
Else -> exit(Else)
end.
or am I missing something more subtle?
Sean
More information about the erlang-questions
mailing list