[erlang-questions] Old school exceptions vs. new age one
Hynek Vychodil
vychodil.hynek@REDACTED
Mon Apr 28 14:39:25 CEST 2008
Because you should use:
> try lists:sort(abc) catch error:Why -> io:format("~p~n", [{Why,
erlang:get_stacktrace()}]) end.
{function_clause,[{lists,sort,[abc]},
{erl_eval,do_apply,5},
{erl_eval,try_clauses,8},
{shell,exprs,6},
{shell,eval_loop,3}]}
ok
On Mon, Apr 28, 2008 at 2:27 PM, Maxim Treskin <zerthurd@REDACTED> wrote:
> Hello
>
> According Pragmatic Programming Erlang there is two syntax of exceptions:
> Old-style:
> <pre>
> case (catch foo(...)) of
> {'EXIT', Why} ->
> ...
> Val ->
> ...
> end
> </pre>
>
> and new-style:
> <pre>
> try foo(...) of
> Val -> ...
> catch
> exit: Why ->
> ...
> end
> </pre>
>
> If I use new-style syntax, I have not detailed exception cause
> explanation, like this:
> <pre>
> 3> try lists:sort([1,2,3]) catch exit:Why -> io:format("~p~n", [Why]) end.
> [1,2,3]
> 4> try lists:sort(abc) catch exit:Why -> io:format("~p~n", [Why]) end.
> ** exception error: function_clause
> </pre>
>
> But if I use old-style syntax, I have this:
> <pre>
> 5> case (catch lists:sort(abc)) of {'EXIT', Why} -> io:format("~p~n",
> [Why]) end.
> {function_clause,[{lists,sort,[abc]},
> {erl_eval,do_apply,5},
> {erl_eval,expr,5},
> {erl_eval,expr,5},
> {shell,exprs,6},
> {shell,eval_exprs,6},
> {shell,eval_loop,3}]}
> ok
> </pre>
>
> Can you say me, why is new-style better than old?
>
> Thank you
>
> --
> Maxim Treskin
> _______________________________________________
> erlang-questions mailing list
> erlang-questions@REDACTED
> http://www.erlang.org/mailman/listinfo/erlang-questions
>
--
--Hynek (Pichi) Vychodil
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://erlang.org/pipermail/erlang-questions/attachments/20080428/27825956/attachment.htm>
More information about the erlang-questions
mailing list