[erlang-questions] handle_info stopped crashing if no match?

Max Lapshin max.lapshin@REDACTED
Sun Feb 25 00:59:19 CET 2018


As for me, we try to _never_  put such code:

handle_info(_UnknownMsg, State) ->
   {noreply, State}.


Such clause catches not only _UnknownMsg, but also  changed State after hot
reload and may cost several hours of debugging.

This is what we try to put in code:

handle_info(_UnknownMsg, #state{} = State) ->
  {noreply, State}.



If record #state{} changes, all processes should not live with old state.


But this is of course a source of error.  More safe is to write:

handle_info(UnknownMsg, #state{} = State) ->
  {stop, {unknown, UnknownMsg}, State}.



You should not ever receive unknown messages in your system. Once you start
adding silent catch-all clause in your system, it will be hard
to stop and hard to find where error begins and ends.
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://erlang.org/pipermail/erlang-questions/attachments/20180225/e6142cb8/attachment.htm>


More information about the erlang-questions mailing list