public
Created

  • Download Gist
gistfile1.txt
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33
-module(stack_trace_test).
-export([
t1/0,
t2/0,
t_all/0
]).
t_all() ->
t1(),
t2().
t1() ->
try e1() of
Res -> Res
catch
throw:{application_error, Error} ->
io:format("t1 error ~p stacktrace ~p~n", [Error, erlang:get_stacktrace()])
end.
t2() ->
try e2() of
Res -> Res
catch
throw:{application_error, Error} ->
io:format("t2 error ~p stacktrace ~p~n", [Error, erlang:get_stacktrace()])
end.
e1() -> throw({application_error, very_bad}).
e2() -> raise_error(very_bad), ok.
raise_error(Error) -> throw({application_error, Error}).

(erlweb@eva)15> stack_trace_test:t_all().
t1 error very_bad stacktrace [{stack_trace_test,e1,0},
{stack_trace_test,t1,0},
{stack_trace_test,t_all,0},
{erl_eval,do_apply,5},
{shell,exprs,7},
{shell,eval_exprs,7},
{shell,eval_loop,3}]
t2 error very_bad stacktrace [{stack_trace_test,raise_error,1},
{stack_trace_test,t2,0},
{erl_eval,do_apply,5},
{shell,exprs,7},
{shell,eval_exprs,7},
{shell,eval_loop,3}]
ok

Please sign in to comment on this gist.

Something went wrong with that request. Please try again.