[erlang-questions] Recommended way to crash gen_server

Fred Hebert mononcqc@REDACTED
Sat Jul 8 15:42:22 CEST 2017


On 07/08, Albin Stigö wrote:
>Regarding crashing, Is the recommended approach to return {stop,
>Reason} or should I exit(Reason) or maybe even throw(Reason).

I would go with {stop, Reason, State}, allowing the gen_server to clean 
up what it may need to (if at all). The Reason returned will be used by 
the behaviour to 'exit' the process all the same.

Do note that the following reasons will *NOT* be seen as abnormal 
terminations, so a transient supervisor will not restart them:

- normal
- shutdown
- {shutdown, Term}

although the latter may be useful to document the type of normal 
expected exit that happened.



More information about the erlang-questions mailing list