[erlang-questions] Programming question

Mats Cronqvist <>
Thu Jan 25 13:08:24 CET 2007

Sean Hinde wrote:
> On 25 Jan 2007, at 08:23, Mats Cronqvist wrote:
>> Sean Hinde wrote:
>>> One fix might be for gen:call() to issue another exit signal towards
>>> the calling process after returning the result.
>>    surely if you catch the exit and it turns out you really wanted it, 
>> you
>> should re-throw?
>>    how about
>> try
>>    Res = gen_server:call(PidA, {op, stuff}),
>>    S1 = process(Res, S),
>>    loopB(PidA, S1)
>> catch
>>    C:R ->
>>      case is_process_alive(PidA) of
>>        true -> loopB(PidA,dosomething({C,R},S));
>>        false -> exit({C,R})
>>      end
>> end
> This would work, but my is it ugly - 

   hey! it took me several seconds to write that code! some respect please :>

> how is anyone supposed to remember 
> to do that every time they want to be sure that the called process has 
> gone down (as opposed to any other reason for the call to thrown an 
> exception).
> The problem as I see it is that the calling process only sometimes get 
> its 'EXIT' message - it depends on context.

   but it does get it's exit message. always. the "context" is that you catch it 
and throw it away...


p.s. i wonder if C and R above (the exception class and reason) will give you 
enough info the distinguish a dead server from other causes of exits.
   maybe it ought to be something like this;

try gen_server:call(PidA, {op, stuff}) of
   Res -> loopB(PidA, process(Res, S))
    exit:{no_proc,_} -> exit(server_was_dead_when_we_called);
    exit:insert_correct_value -> exit(server_died_while_processing);
    C:R -> loopB(PidA,handle_other_errors({C,R},S))

   the 4 branches here are unavoidable, i think, since there are 4 different 
outcomes to the gen_server call.

More information about the erlang-questions mailing list