Skip to content

Instantly share code, notes, and snippets.

@UnisonPublic
Created December 15, 2011 08:09
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save UnisonPublic/1480320 to your computer and use it in GitHub Desktop.
Save UnisonPublic/1480320 to your computer and use it in GitHub Desktop.
-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}).
@UnisonPublic
Copy link
Author

(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

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment