考虑下面的代码:
-module(except).
-compile(export_all).
divone(X)-> erlang:error({badnews,erlang:get_stacktrace()}),1/X-1.
tryreturn(X)->
try divone(X) of
Val->{result,2/Val}
catch
exit:Reason->{exit,Reason};
throw:Throw->{throw,Throw};
error:Error->{error,Error}
end.
在shell中测试代码:
Eshell V5.9.1 (abort with ^G)
1> c(except).
{ok,except}
2> except:tryreturn(10). **%why cant't get stack trace info here?**
{error,{badnews,[]}}
3> except:tryreturn(10). **%why can get here?**
{error,{badnews,[{except,divone,1,
[{file,"except.erl"},{line,4}]},
{except,tryreturn,1,[{file,"except.erl"},{line,7}]},
{erl_eval,do_apply,6,[{file,"erl_eval.erl"},{line,576}]},
{shell,exprs,7,[{file,"shell.erl"},{line,668}]},
{shell,eval_exprs,7,[{file,"shell.erl"},{line,623}]},
{shell,eval_loop,3,[{file,"shell.erl"},{line,608}]}]}}