[erlang-questions] Exceptions and gen_server

Anton Krasovsky <>
Sat Nov 7 22:53:27 CET 2009


True, I'd normally just print unexpected requests, but it's better this way.

Anton

On Sat, Nov 7, 2009 at 9:42 PM, Vance Shipley <> wrote:
> On Sat, Nov 07, 2009 at 09:33:33PM +0000, Anton Krasovsky wrote:
> }  I suppose you'd get better stack trace in my case, but also I didn't
> }  realize you can do exit(Pid, Reason) to a caller process.
>
> I do use this method to handle unknown calls in servers where I'd
> rather the server kept running than have it fail and expose a
> programming error in another process.
>
>        handle_call(Request, From, State) ->
>                ...
>                {reply, Reply, State};
>        handle_call(_Request, {Pid, _Tag}, State) ->
>                exit(Pid, badarg),
>                {noreply, State}.
>
> This way if some process attempts gen_server:call(S, foo), where
> foo is not a supported API call, they get the appropriate response.
>
> --
>        -Vance
>


More information about the erlang-questions mailing list