[erlang-questions] try .. of .. catch question

Jeroen Koops <>
Wed Feb 9 12:31:25 CET 2011


Hi Dave,

The two blocks are different. In the first block, if an exception occurs
anywhere between the 'case' and the 'end', it will be caught by the
catch-clause. But in the second block, only exceptions occurring when
evaluating foo() will be caught; exceptions occuring while evaluating 'a' or
'b' won't.

Regards,

Jeroen



On Wed, Feb 9, 2011 at 12:22 PM, Dave Challis <> wrote:

> Hi,
> I'm just learning about exceptions in Erlang, and just curious as to the
> use of try..of..catch - is it just a shortcut to combining a case with a
> try/catch?
>
> For example, are the two blocks of code below identical? Or is there some
> subtle difference I've missed?
>
> try
>    case foo() of
>        true  -> a;
>        false -> b
>    end
> catch
>    Error:Reason -> {Error, Reason}
> end
>
>
> try
>    foo()
> of
>    true  -> a;
>    false -> b
> catch
>    Error:Reason -> {Error, Reason}
> end
>
> Thanks,
> --
> Dave Challis
> 
>
> ________________________________________________________________
> erlang-questions (at) erlang.org mailing list.
> See http://www.erlang.org/faq.html
> To unsubscribe; mailto:
>
>


More information about the erlang-questions mailing list