[Date Index]
[Thread Index]
[Author Index]
Re: Limiting the number of messages
*To*: mathgroup at smc.vnet.net
*Subject*: [mg103830] Re: [mg103810] Limiting the number of messages
*From*: Sean McConnell <smcconne at physi.uni-heidelberg.de>
*Date*: Thu, 8 Oct 2009 07:51:24 -0400 (EDT)
*References*: <200910071102.HAA00467@smc.vnet.net>
Actually I've found a reasonably good way of dealing with what I'm
talking about. See below...
f[a_, b_] /;
If[a > 0,
True,
Message[f::aerror]
] &&
If[b > 2,
True,
Message[f::berror]
] := a + b;
f::aerror = "a is too small";
f::berror = "b is too small";
t[a_, b_] :=
If[Check[f[a, b]^2, "Error"] === "Error",
"t(" <> StringJoin[Riffle[ToString /@ {a, b}, ","]] <> ")",
f[a, b]^2
];
In[23]:=
t[0, 3]
t[1, 2]
t[0, 2]
t[1, 3]
During evaluation of In[23]:= f::aerror: a is too small
Out[23]= t(0,3)
During evaluation of In[23]:= f::berror: b is too small
Out[24]= t(1,2)
During evaluation of In[23]:= f::aerror: a is too small
During evaluation of In[23]:= f::berror: b is too small
Out[25]= t(0,2)
Out[26]= 16
I realise it's a bit amateur to be re-writing the input as a string for
the output (well, actually the whole thing feels more like a work-around
than a proper solution), but it's achieving what I'm after I guess?!?
Am Mittwoch, den 07.10.2009, 07:02 -0400 schrieb Sean McConnell:
> Hi,
>
> I'm creating a program with procedures that often depend on
> sub-procedures. Many times I allow the sub-procedures to do the input
> checking, so I don't have to write a the same error trapping conditions
> and messages for each level of the program. The problem is however that
> although the 'input checking' is passed on to a sub-procedure, the main
> procedure continues to attempt to evaluate, and can usually return a
> very long list of error messages whilst it foolishly attempting to
> evaluate with improperly input variables.
>
> I would like to know how to make a procedure abort its evaluation after
> say 3 or so messages, and simply return the name of the procedure and
> the variables (as happens when you use /; for conditionals). I have
> tried the use of Check[], and although it checks for messages, it will
> only return what is typed in to the space for a second argument (eg:
> Check[f[a], "problem"] will return simply "problem"), I would like to be
> able to tell the user how they have screwed up.
>
> Many thanks,
>
> Sean McConnell.
>
>
Prev by Date:
**Re: For interest: oil prices with FX for comparison**
Next by Date:
**Re: Re: generating submultisets with repeated elements**
Previous by thread:
**Limiting the number of messages**
Next by thread:
**Re: Limiting the number of messages**
| |