catching errors from linked processes: simplest way?

Ulf Wiger etxuwig@REDACTED
Wed Apr 23 00:55:54 CEST 2003


How about writing a small library function:


assert(false, Msg) ->
   exit(Msg);
assert(true, _) ->
   true.


foo(A, B) ->
   assert(A, only_applies_under_condition_a),
   bar(B).


/Uffe

On Tue, 22 Apr 2003, Chris Pressey wrote:

>However, I got to another sticking point.  I have several functions that
>only make sense under a certain condition, let's call it A.  The
>functions used to look like this:
>
>  foo(A, B) ->
>    case A of
>      true ->
>        bar(B);
>      false ->
>        {error, only_applies_under_condition_a}
>    end.
>
>Now, they look like this:
>
>  foo(A, B) ->
>    A = true, bar(B).
>
>which is *much* easier to read.  :)
>
>However, the error message has gone from a nice,
>informative one, to the generic {badmatch, true}, which is
>not all that great (I'd like to be able to give the
>(probably non-Erlang-literate) user a message as to exactly
>why it crashed.)

-- 
Ulf Wiger, Senior Specialist,
   / / /   Architecture & Design of Carrier-Class Software
  / / /    Strategic Product & System Management
 / / /     Ericsson AB, Connectivity and Control Nodes




More information about the erlang-questions mailing list