Skip to content

Commit

Permalink
Merge pull request #69 from getong/fix_get_stacktrace
Browse files Browse the repository at this point in the history
deprecated erlang:get_stacktrace/0 function
  • Loading branch information
willemdj committed Jan 16, 2019
2 parents af539d4 + 1f2c2f5 commit a5069fb
Show file tree
Hide file tree
Showing 4 changed files with 13 additions and 3 deletions.
7 changes: 7 additions & 0 deletions include/exception.hrl
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
-ifdef(OTP_RELEASE). %% this implies 21 or higher
-define(EXCEPTION(Class, Reason, Stacktrace), Class:Reason:Stacktrace).
-define(GET_STACK(Stacktrace), Stacktrace).
-else.
-define(EXCEPTION(Class, Reason, _), Class:Reason).
-define(GET_STACK(_), erlang:get_stacktrace()).
-endif.
3 changes: 2 additions & 1 deletion src/erlsom.erl
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,7 @@
add_file/3, add_xsd_model/1, add_model/2]).

-include("erlsom.hrl").
-include("exception.hrl").
-include("erlsom_parse.hrl").

-type characters() :: string() | binary().
Expand Down Expand Up @@ -261,7 +262,7 @@ scan_file(File, Model, Options) ->
catch
throw:Reason -> {error, Reason};
exit:Reason -> throw({'EXIT',Reason});
error:Reason -> throw({'EXIT',{Reason,erlang:get_stacktrace()}})
?EXCEPTION(error, Reason, Stacktrace) -> throw({'EXIT',{Reason, ?GET_STACK(Stacktrace)}})
end;
Error ->
Error
Expand Down
3 changes: 2 additions & 1 deletion src/erlsom_parse.erl
Original file line number Diff line number Diff line change
Expand Up @@ -172,6 +172,7 @@
-export([new_state/1]).
-export([new_state/2]).
-include("erlsom.hrl").
-include("exception.hrl").
-include("erlsom_sax.hrl").
-include("erlsom_parse.hrl"). %% the record definitions
-import(erlsom_lib, [findType/6]).
Expand Down Expand Up @@ -345,7 +346,7 @@ xml2StructCallback(Event, State) ->
exit(Message)
end
catch
error:Reason -> throwError(error, {Reason,erlang:get_stacktrace()}, Event, State);
?EXCEPTION(error, Reason, Stacktrace) -> throwError(error, {Reason, ?GET_STACK(Stacktrace)}, Event, State);
Class:Exception -> throwError(Class, Exception, Event, State)
end.

Expand Down
3 changes: 2 additions & 1 deletion src/erlsom_simple_form.erl
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@
-export([new_state/1]).

-include("erlsom_sax.hrl").
-include("exception.hrl").

-record(sState, {stack, nameFun, options}).

Expand Down Expand Up @@ -93,7 +94,7 @@ callback(Event, State) ->
exit(Message)
end
catch
error:Reason -> throwError(error, {Reason,erlang:get_stacktrace()}, Event, State);
?EXCEPTION(error, Reason, Stacktrace) -> throwError(error, {Reason, ?GET_STACK(Stacktrace)}, Event, State);
Class:Exception -> throwError(Class, Exception, Event, State)
end.

Expand Down

0 comments on commit a5069fb

Please sign in to comment.