erlang:fault/1 vs. erlang:exit/1
Luke Gorrie
luke@REDACTED
Tue May 30 13:39:02 CEST 2006
Howdy,
Just a friendly reminder that thanks to Richard Carlsson's EUC talk we
know that the best way to signal a crash-error is by calling
erlang:fault(Reason) and not erlang:exit(Reason). This is because
'fault' will helpfully wrap the crash reason with a backtrace saying
where it comes from whereas exit will not.
Example:
8> catch erlang:fault(foo).
{'EXIT',{foo,[{erl_eval,do_apply,5},
{erl_eval,expr,5},
{shell,exprs,6},
{shell,eval_loop,3}]}}
9> catch erlang:exit(foo).
{'EXIT',foo}
This makes crashes caused by 'fault' much easier to track down than
ones caused by 'exit'. I suggest using 'fault' as your default choice.
I was a bit confused today while trying to track down a crash with
reason 'badarg' (no backtrace) which turned out to come from an 'exit'
in gen_tcp:connect/4. Maybe that could be a 'fault' instead.
Cheerio,
-Luke
More information about the erlang-questions
mailing list