why catch gen_server; MOD:handle_call?
Martin J. Logan
Thu Jul 8 00:08:24 CEST 2004
The terminate function is called when a call back in a gen server fails.
I am wondering if this is a good idea or not. This opens up doors for
inconsistencies. Here is an example chronology:
1. gen_server:call(?SERVER, do_something).
2. handle_call(do_something, From, State) ->
-Side effects and a corresponding state alteration to StatePrime
-exit with a badmatch before returning StatePrime
3. terminate(Badmatch, State) -> % Note State as it was before the side
effects that happend in handle_call not StatePrime
Sideffects similar to those in handle_call based on State.
This can leave a system in a bad state. The catch seems to violate the
"let it die" tennant that is so crucial to good erlang programming as
well as the good ol' principle of least astonishment. This code might
work as expected if we were using a language that encouraged a lack of
referential transparency i.e state is preferably stored in a process
dictionary. This badmatch error is a problem with the code and might be
handled more effectively by a supervision structure rather than a
More information about the erlang-questions