catching errors from linked processes: simplest way?

Chris Pressey cpressey@REDACTED
Tue Apr 22 23:44:32 CEST 2003

On Tue, 22 Apr 2003 15:35:16 -0500
Chris Pressey <cpressey@REDACTED> wrote:

> If I do the translation in the client, I would have:
>   foo(A, B) ->
>     case A of
>       true ->
>         bar(B);
>       false ->
>         throw(only_applies_under_condition_a)
>     end.
> which is hardly any improvement over the original.

Ah!  I think I see a compromise: notify the supervisor of the nature of
any potential upcoming errors.  So the code becomes something like:

  foo(A, B) ->
    supervisor:potential_error(only_applies_under_condition_a, [A,B]),
    A = true, bar(B).

where supervisor:potential_error/2 sends a message to the supervisor,
which stores it in a dictionary using the pid the message came from as
the key, and which retrieves it when an error actually does occur.

The code is still fairly easy to read, and the supervisor doesn't need
to know about the structure of the code it's supervising, yet it can
know some details about what state the process was in when it crashed. 



More information about the erlang-questions mailing list