Exception handling idioms

Bengt Kleberg bengt.kleberg@REDACTED
Thu Aug 25 12:33:49 CEST 2005


On 2005-08-25 12:02, Tim Bates wrote:
> 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?

how about this. you change the 3;rd line to:

	ok = gen_server:call(Pid, {insert, Value}),

and have handle_call/2 return {reply, bad_input, State} instead of 
{reply, ok, State}.


bengt



More information about the erlang-questions mailing list