[erlang-questions] Why can not catch exception in gen_server init callback function?
Paul Davis
paul.joseph.davis@REDACTED
Wed Mar 31 18:09:41 CEST 2010
On Wed, Mar 31, 2010 at 11:48 AM, 钱晓明 <kyleqian@REDACTED> wrote:
> Hi, Why can not catch exception in gen_server init callback function?
>
> init([]) ->
> erlang:error(myerror),
> {ok, #state{}}.
>
> Ex = (catch myserver:start_link()).
>
> process is terminated by exception myerror, but Ex is still unbound. Why?
>
I've found that using proc_lib:start_link, proc_lib:init_ack and
gen_server:enter_loop to be a very clean way to start gen_servers that
might fail during initialization. No idea if that's proper or not, but
it's treated me pretty well.
HTH,
Paul Davis
More information about the erlang-questions
mailing list