[erlang-questions] Associating contextual info with monitors

Andras Georgy Bekes bekesa@REDACTED
Mon Feb 18 12:44:26 CET 2008


> For instances where the processes being spawned aren't gen_* servers,
> I would most likely spawn a wrapper process which in turn spawn_links
> the real child process, then blocks forever waiting to receive the
> EXIT for that process (the cleanup code is triggered upon receipt of
> the EXIT, then the wrapper process itself terminates).
So you write something like this:
-----
Worker=spawn_link(fun()->
                doit()
             end),
receive
   {'EXIT',Worker,Reason}->
      cleanup()
end
-----

Isn't it simpler to write
-----
try
   doit()
catch
   Class:Error ->
      do_something(Class,Error)
after
      cleanup()
end
-----
?
This doesn't use the extra process, and anyways, isn't this the purpose 
of try-catch? You can even omit the catch section, it is not mandatory.

	Georgy



More information about the erlang-questions mailing list