[erlang-questions] Heads-up: The cost of get_stacktrace()
Richard Carlsson
carlsson.richard@REDACTED
Sun Nov 10 15:15:37 CET 2013
On 2013-11-10 13:39, Anthony Ramine wrote:
> Could your system use erlang:raise(error, {foo,{Class,Term}}, erlang:get_stacktrace()) instead of returning things?
Probably, but the (somewhat convoluted) logic needs to be rewritten to
catch that exception further up instead of expecting an error tuple as
the return value. We'll either be doing something along those lines, or
avoid the need for an intermediate catch altogether.
> The call to erlang:get_stacktrace() could then be optimized away by the compiler and no informations would be lost ever.
Interesting idea, and might be worth doing. You'd have to be sure that
the un-expanded stack dump only gets passed into the third arg of
raise/3, and doesn't escape to any other Erlang code.
Just note that re-throwing with raise/3 should be used very carefully.
If you substitute the exception class and term while keeping the stack
trace pointing to where the original exception occurred, someone trying
to debug the crash might then look at the source code at that point,
realize there's no way it could result in that kind of exception, and be
greatly confused. It's generally preferable to re-throw only with the
exact same class/term.
/Richard
More information about the erlang-questions
mailing list