Re: Limiting the number of messages
- To: mathgroup at smc.vnet.net
- Subject: [mg103816] Re: Limiting the number of messages
- From: Albert Retey <awnl at gmx-topmail.de>
- Date: Thu, 8 Oct 2009 07:48:48 -0400 (EDT)
- References: <hahsi2$jm$1@smc.vnet.net>
Sean McConnell wrote: > 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. I think the best approach is probably to use a combination of Catch and Throw. I would probably replace all occurances of Message within your code by something like myMessage and define myMessage to print the message, increase a counter and if the counter is higher than a given limit call Throw. The outmost routine will then just need to be wrapped with Catch. Of course there are various possibilities how you can fine tune that approach. Most of that you can learn from the documentation for Catch and Throw. hth, albert