Exception handling idioms

Raimo Niskanen raimo@REDACTED
Thu Aug 25 15:25:50 CEST 2005

If the gen_server crashes during the call, the library function
gen_server:call/2 detects this using monitors, and returns an
error value. You should only use a link if you want the client
process to die when the server dies even while the client is not
doing a call to the server.

tim@REDACTED (Tim Bates) writes:

> Hi folks,
> I have a gen_server process, which if an error occurs inside it due to
> bad input I want to force the caller to crash. I find myself doing
> this a lot:
> insert(Pid, Value) ->
>    link(Pid),
>    gen_server:call(Pid, {insert, Value}),
>    unlink(Pid),
>    ok.
> Is this a common idiom? Is it a reasonable thing to do? It has the
> downside that the server crashes too, which is reasonable in some
> cases and somewhat unnecessary in others. How else might I do this?
> Also, somewhat offtopic for this post, does anyone know of any
> fixed-point-arithmetic or manipulating-binaries-as-strings libraries
> in Erlang? Both of these would come in handy for this project.
> Tim.
> -- 
> Tim Bates


/ Raimo Niskanen, Erlang/OTP, Ericsson AB

More information about the erlang-questions mailing list