[erlang-questions] Unexpected try/catch behaviour
Wed Feb 24 01:28:33 CET 2010
On Tue, Feb 23, 2010 at 5:36 PM, Bernard Duggan <bernie@REDACTED> wrote:
> Richard O'Keefe wrote:
>> When is it appropriate to use try E of H catch ... end
>> instead of try case E of H end catch ... end?
> When you want to use tail recursion.
> The recursive call to foo() here:
> foo(X) ->
> case f(X) of
> A -> foo(A);
> _ -> ok
> _ -> doom()
> Is /not/ tail recursive on account of the catch block.
Another problem with that block is that you don't know whether the
exception originated from f(X) or foo(A).
The beauty of try...of is that you isolate the code your trying.
More information about the erlang-questions