-
Notifications
You must be signed in to change notification settings - Fork 29
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #28 from stritzinger/otp-21-stacktrace-compatibility
Add compatibility for OTP 21+ stack traces
- Loading branch information
Showing
3 changed files
with
45 additions
and
8 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,33 @@ | ||
%% Originating from Quviq AB | ||
%% Fix to make Erlang programs compile on both OTP20 and OTP21. | ||
%% | ||
%% Get the stack trace in a way that is backwards compatible. Luckily | ||
%% OTP_RELEASE was introduced in the same version as the new preferred way of | ||
%% getting the stack trace. A _catch_/2 macro is provided for consistency in | ||
%% cases where the stack trace is not needed. | ||
%% | ||
%% Example use: | ||
%% try f(...) | ||
%% catch | ||
%% ?_exception_(_, Reason, StackToken) -> | ||
%% case Reason of | ||
%% {fail, Error} -> ok; | ||
%% _ -> {'EXIT', Reason, ?_get_stacktrace_(StackToken)} | ||
%% end | ||
%% end, | ||
|
||
-ifdef(OTP_RELEASE). %% This implies 21 or higher | ||
-define(_exception_(Class, Reason, StackToken), Class:Reason:StackToken). | ||
-define(_get_stacktrace_(StackToken), StackToken). | ||
-define(_current_stacktrace_(), | ||
try | ||
exit('$get_stacktrace') | ||
catch | ||
exit:'$get_stacktrace':__GetCurrentStackTrace -> | ||
__GetCurrentStackTrace | ||
end). | ||
-else. | ||
-define(_exception_(Class, Reason, _), Class:Reason). | ||
-define(_get_stacktrace_(_), erlang:get_stacktrace()). | ||
-define(_current_stacktrace_(), erlang:get_stacktrace()). | ||
-endif. |