[erlang-questions] Programming question

Ulf Wiger ulf@REDACTED
Fri Jan 26 09:27:33 CET 2007


Den 2007-01-26 09:01:22 skrev Samuel Rivas <samuelrivas@REDACTED>:

>     handle_call(trhow_it, _From, State) ->
>         throw(ouch),
>         {reply, ok, State};
>    handle_call(weird, _From, State) ->
>         throw({reply, ok, State}),
>         {stop, ok, State};
>    handle_call(expected, _From, State) ->
>         erlang:error({nocatch, ouch}),
>         {reply, ok, State}.

[...]

>  - I would expect that 'throw_it' caused an exception similar
>     to 'expected' (with the right stack trace)

The exception in this case is raised by the gen_server module,
which expects a return value from Mod:handle_call/3 to be
{reply,Rep,S1} | {noreply,S1} | {stop,Reason,S1}
| {stop,Rep,Reason,S1}

'ouch' doesn't qualify as a valid return value.

In the case of 'expected', your code raises an exception,
which is caught by the gen_server module, which adds some
info (e.g. last message) and then exits (I'm not looking
at the code - can't remember if it calls exit/1 or error/1.)


>   - I would expect that 'weird' caused a similar exception too,
>     but it does not even crash the server.

...because gen_server uses an old-style catch, and therefore
cannot tell the difference between your thrown value and a
normal (and legal) return value.


-- 
Ulf Wiger



More information about the erlang-questions mailing list