Problem with trap_exit

Alexander Harju alexander.harju@REDACTED
Fri Aug 18 15:18:24 CEST 2006

Yeah, that make sense. If you have a supervisor you really don't want 
children to be able to trap exit. It would end up with pretty 
interesting restarts. It must be considered to be a weak design if you 
let a linked child-process ignore a crash of the parent anyway. I wasn't 
actually planing to use this structure at all but I noticed it when 
working on test-tool and I couldn't find anything about it the 
Find a way of go around it tho. Either start the child without link and 
then link it and trap exit or use a monitor of the parent and receive 
the {'DOWN',...}-message.
Thanks for the response.
// Alex

Ulf Wiger wrote:

>>Hi all.
>>I'm having some problem trying to trap an exit in a gen_fsm.
>>I've made this small example of the problem attached to this mail. It's
>>a gen_server (test_server.erl) that starts a gen_fsm (test_fsm.erl)
>>using gen_fsm:start_link(...)
>>When I by purpose crash the server I expect that the
>>handle_info-function in the state-machine to handle the {'EXIT',
>>...}-signal since I've turned on trap_exit.
>>Instead the terminte is called with the reason for the crash.
>>Why is the signal not traped?
>>// Alex
>It _is_ trapped - otherwise, terminate() wouldn't be called.
>Most likely, the main loop in gen_fsm is trapping the exit,
>which it does if the 'EXIT' message comes from the parent
>process. The thinking is that the parent process is most
>likely a supervisor, and the gen_fsm process a worker process.
>It then makes sure that it's not 'orphaned'.
>If you test your program from the shell, try unlinking the
>gen_fsm process, then killing the shell process (call
>exit(foo) at the shell prompt), and then link to the fsm
>process from the new shell process.
>Ulf W

More information about the erlang-questions mailing list