[erlang-questions] Programming question

Sean Hinde sean.hinde@REDACTED
Thu Jan 25 13:26:43 CET 2007


On 25 Jan 2007, at 12:08, Mats Cronqvist wrote:

> 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 :>

Heh Heh. OK, It's beautiful code, if it makes you feel better, but as  
a required construct it is still ugly :-)


>>
>> 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...

No! Receiving an exit message is different to catching an exception.  
The problem is that the gen_server:call mechanism does just that, it  
catches an exit message from the called process and turns it into a  
simple exception.

This is why I suggest that *if* the exception thrown by  
gen_server:call was actually caused by an exit message from the  
called process then the gen_server should throw the exception *and*  
resend the EXIT message to the called process.

Sean






More information about the erlang-questions mailing list