[erlang-questions] Exceptions and gen_server

Vance Shipley vances@REDACTED
Sat Nov 7 22:42:08 CET 2009


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