escript_runtime: remove support for OTP < 21

This commit is contained in:
Mikael Pettersson 2019-12-30 14:00:00 +01:00
parent 3727dfbcc9
commit b96d413aaf

View File

@ -1,7 +1,7 @@
%%% -*- erlang-indent-level: 2 -*-
%%%
%%% Runtime support for stand-alone programs started as escripts.
%%% Copyright (C) 2018 Mikael Pettersson
%%% Copyright (C) 2018-2019 Mikael Pettersson
%%%
%%% This file is part of pdp10-tools.
%%%
@ -27,22 +27,12 @@
, start/2
]).
%% TODO: drop these macros when dropping support for OTP < OTP-21
-ifdef(OTP_RELEASE). % >= OTP-21
-define(EXN_WITH_STACKTRACE(Class, Reason, Stacktrace), Class:Reason:Stacktrace).
-define(GET_STACKTRACE(Stacktrace), ok).
-else. % < OTP-21
-define(EXN_WITH_STACKTRACE(Class, Reason, Stacktrace), Class:Reason).
-define(GET_STACKTRACE(Stacktrace), Stacktrace = erlang:get_stacktrace()).
-endif.
%% escript logs unhandled exceptions to standard output, but we want them to
%% end up on standard error
start(Main, Argv) ->
try
Main(Argv)
catch ?EXN_WITH_STACKTRACE(Class, Reason, Stacktrace) ->
?GET_STACKTRACE(Stacktrace),
catch Class:Reason:Stacktrace ->
fmterr("~s: Unhandled exception ~p:~p\n~p\n", [progname(), Class, Reason, Stacktrace]),
halt(1)
end.