[erlang-questions] try .. of .. catch question
Raimo Niskanen
raimo+erlang-questions@REDACTED
Wed Feb 9 13:15:55 CET 2011
One more subtle difference: in the first block if foo() returns
something other than true or false, the case clause generated
will be caught by the catch clause, but in the second block
a try clause will be generated and not caught by the catch
clause since it out of scope of the try..catch.
On Wed, Feb 09, 2011 at 12:31:25PM +0100, Jeroen Koops wrote:
> 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 <dsc@REDACTED> 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
> > dsc@REDACTED
> >
> > ________________________________________________________________
> > erlang-questions (at) erlang.org mailing list.
> > See http://www.erlang.org/faq.html
> > To unsubscribe; mailto:erlang-questions-unsubscribe@REDACTED
> >
> >
--
/ Raimo Niskanen, Erlang/OTP, Ericsson AB
More information about the erlang-questions
mailing list