catching errors from linked processes: simplest way?

Vladimir Sekissov svg@REDACTED
Tue Apr 22 08:28:34 CEST 2003


Good day,

cpressey> I guess what I'm thinking is, wouldn't it be great if 'catch' could
cpressey> catch errors from linked processes.  I guess I'm also thinking that
cpressey> someone's probably thought of this before, so there's probably a simple

You are catching exit message , it is in your mailbox:

start() ->
  Pid = spawn_link(?MODULE, server, []),
  case catch client(Pid, [10, 20, 30, 50, abba, 80, 90, 180]) of
    ok ->
      io:fwrite("all OK~n"),
      receive
	{'EXIT', Pid, Reason} ->
	  io:fwrite("not OK: ~p~n", [Reason])
      after 0 ->
	  ok
      end;
    Else ->
      io:fwrite("not OK: ~p~n", [Else])
  end.

3> test3:start().
not OK: {'EXIT',{badarith,[{test3,client,2},
                           {test3,start,0},
                           {erl_eval,expr,3},
                           {erl_eval,exprs,4},
                           {shell,eval_loop,2}]}}
got "11"
...

Best Regards,
Vladimir Sekissov



More information about the erlang-questions mailing list