logo       

Re: catching errors from linked processes: simplest way?: msg#00325

lang.erlang.general

Subject: Re: catching errors from linked processes: simplest way?


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




<Prev in Thread] Current Thread [Next in Thread>
Google Custom Search

News | FAQ | advertise