diff options
author | Zandra Norman <[email protected]> | 2017-04-24 11:07:36 +0200 |
---|---|---|
committer | Zandra Norman <[email protected]> | 2017-04-24 11:07:36 +0200 |
commit | 37158d81c8a49d77b8ba32dbc560b3064127e24d (patch) | |
tree | 43b00d680f459571b2d3d60b874fbdcfdad62eca /lib/stdlib/src/gen_server.erl | |
parent | 3ab6bcf6f9a44c998610bdf8863c07fb4f221da9 (diff) | |
parent | 9e396c8676e5a7eacbe5e7b2d93ee080298eb8fb (diff) | |
download | otp-37158d81c8a49d77b8ba32dbc560b3064127e24d.tar.gz otp-37158d81c8a49d77b8ba32dbc560b3064127e24d.tar.bz2 otp-37158d81c8a49d77b8ba32dbc560b3064127e24d.zip |
Merge branch 'zandra/stdlib/optional-callbacks/OTP-13801'
* zandra/stdlib/optional-callbacks/OTP-13801:
wx: make wx_object callbacks optional
stdlib: Make gen_fsm callbacks optional
stdlib: Make gen_event callbacks optional
stdlib: Make gen_server callbacks optional
Diffstat (limited to 'lib/stdlib/src/gen_server.erl')
-rw-r--r-- | lib/stdlib/src/gen_server.erl | 42 |
1 files changed, 29 insertions, 13 deletions
diff --git a/lib/stdlib/src/gen_server.erl b/lib/stdlib/src/gen_server.erl index 284810c971..8504af86f8 100644 --- a/lib/stdlib/src/gen_server.erl +++ b/lib/stdlib/src/gen_server.erl @@ -146,8 +146,8 @@ State :: term(), Status :: term(). --optional_callbacks([format_status/2]). - +-optional_callbacks( + [handle_info/2, terminate/2, code_change/3, format_status/2]). %%% ----------------------------------------------------------------- %%% Starts a generic server. @@ -602,6 +602,17 @@ try_dispatch(Mod, Func, Msg, State) -> catch throw:R -> {ok, R}; + error:undef = R when Func == handle_info -> + case erlang:function_exported(Mod, handle_info, 2) of + false -> + error_logger:warning_msg("** Undefined handle_info in ~p~n" + "** Unhandled message: ~p~n", + [Mod, Msg]), + {ok, {noreply, State}}; + true -> + Stacktrace = erlang:get_stacktrace(), + {'EXIT', {R, Stacktrace}, {R, Stacktrace}} + end; error:R -> Stacktrace = erlang:get_stacktrace(), {'EXIT', {R, Stacktrace}, {R, Stacktrace}}; @@ -625,17 +636,22 @@ try_handle_call(Mod, Msg, From, State) -> end. try_terminate(Mod, Reason, State) -> - try - {ok, Mod:terminate(Reason, State)} - catch - throw:R -> - {ok, R}; - error:R -> - Stacktrace = erlang:get_stacktrace(), - {'EXIT', {R, Stacktrace}, {R, Stacktrace}}; - exit:R -> - Stacktrace = erlang:get_stacktrace(), - {'EXIT', R, {R, Stacktrace}} + case erlang:function_exported(Mod, terminate, 2) of + true -> + try + {ok, Mod:terminate(Reason, State)} + catch + throw:R -> + {ok, R}; + error:R -> + Stacktrace = erlang:get_stacktrace(), + {'EXIT', {R, Stacktrace}, {R, Stacktrace}}; + exit:R -> + Stacktrace = erlang:get_stacktrace(), + {'EXIT', R, {R, Stacktrace}} + end; + false -> + {ok, ok} end. |