loop exit question

Robert Virding <>
Thu Apr 19 14:53:19 CEST 2001


Willem Broekema <> writes:
> ...
>Now, if the State is not changed in any of the 'reveiced'
>branches, is there a reason not to move the final 'loop()'
>command to the end, and use 'exit()' for breaking out of
>the loop, like in the following?
>
>loop2(State) ->
>   receive
>       stop ->
>           exit(self(), stopped_upon_request);
>       Other ->
>           ...
>   end,
>   loop(State).

NOTE!!!!  Exit/2 sends an exit signal to a process, so
exit(self(),xxx) sends an exit signal to itself.  This is *NOT* the
same as calling exit(xxx)!!!

The exit/2 signal can be trapped while exit/1 cannot, while exit/1 can
be caught (in a catch) while exit/2 signals cannot.  You have to be
careful to choose the "right" one.

This difference is intentional.

        Robert



More information about the erlang-questions mailing list