[erlang-questions] Programming question
Mats Cronqvist
mats.cronqvist@REDACTED
Thu Jan 25 09:23:33 CET 2007
Sean Hinde wrote:
>
> There was an error in my example. gen_server does indeed do the right
> thing in this case. The problem occurs in this code:
>
> loopB(PidA, S) ->
> Res = (catch gen_server:call(PidA, {op, stuff})),
> S1 = process(Res, S),
> loopB(PidA, S1).
> Here the gen_server:call catches the {'EXIT', Reason} signal from the
> dying B process and turns it into a call to exit(Reason).
>
> process B just gets an {'EXIT', Reason} result to the call, but it
> doesn't know if Process A is still alive (there can be several
> reasons for the {'EXIT', Reason}.
> 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
mats
More information about the erlang-questions
mailing list