Mathematica 9 is now available
Services & Resources / Wolfram Forums
MathGroup Archive
*Archive Index
*Ask about this page
*Print this page
*Give us feedback
*Sign up for the Wolfram Insider

MathGroup Archive 2006

[Date Index] [Thread Index] [Author Index]

Search the Archive

(Revisited) Intercepting and Controlling Mathematica Exceptions.

  • To: mathgroup at
  • Subject: [mg72106] (Revisited) Intercepting and Controlling Mathematica Exceptions.
  • From: "Philipp" <Philipp.M.O at>
  • Date: Mon, 11 Dec 2006 04:55:54 -0500 (EST)

(Revisited) Intercepting and Controlling Mathematica Exceptions.

The MessagesAbort code addresses the problem of intercepting and
controlling Mathematica exceptions that generate Messages.

My posting from December 2, 2006
contained syntax errors inadvertently introduced by the posting text
processor (it puts SPACE character after each line. If \ is used as the
continuation character, Mathematica interprets it as a back-quoted
space, which causes a syntax error).

Hopefully, the code below is correct. If not, please email me & I'll
send you a text file containing the MessagesAbort definition.

The MessagesAbort[] Code begins at the next line


(******** REPOSTED MessagesAbort (Message OVERLOAD)  ********)

MessagesAbort::usage =
"\[FilledSmallSquare] On[MessagesAbort[symbol::\"tag\", ...]] and "<>
"Off[AbortMessage[]] extend the Mathematica exception handling "<>

"\n\[FilledSmallSquare] On[MessagesAbort[]] transparently sets the "<>
"environment that any Message[symbol::\"tag\"] generated (printed) "<>
"by Mathematica aborts calculations immediately."<>

"\n\[FilledSmallSquare] On[AbortMessages[symbol::\"tag\", ...]] "<>
"sets the environment to abort immediately but only after any of "<>
"the symbol::\"tag\", ... messages is generated."<>

"\n\[FilledSmallSquare] Off[AbortMessage[]] restores the exception "<>
"handling capacity to the Mathematica default."<>

"\n\[FilledSmallSquare] On[symbol::\"tag\", ...] and "<>
"Off[symbol::\"tag\", ...] take precedence over "<>
"On[MessagesAbort[symbol:: \"tag\", ...]], i.e.,\n\t(Off[s::t]; "<>
"On[MessagesAbort[s::t]]) will neither generate the Message[s::t] "<>
"nor will it abort the calculations."

On[MessagesAbort[msgNames___MessageName]] ^:=
   (Unprotect[Message, $MessagesAbortQ];
    $MessagesAbortQ = False;
    Message[args___] := (Check[Block[{$MessagesAbortQ = False},
          Message[args]], Abort[], msgNames]) /; $MessagesAbortQ;
    $MessagesAbortQ = True;
   Protect[Message, $MessagesAbortQ];);

Off[MessagesAbort[]] ^:=
   (Unprotect[Message, $MessagesAbortQ];
    $MessagesAbortQ = False;
   Protect[Message, $MessagesAbortQ];);

SetAttributes[MessagesAbort, HoldAll];

End[(* System` *)]

The MessagesAbort[] Code ends at the previous line.

I suggest that MessagesAbort[] Code is put initially in the Kernel
init.m file in
(...\Wolfram Research\Mathematica\5.2\Configuration\Kernel) directory.

Please feel free to comment on the code, suggest improvements and
point out any faults. Treat it as harshly as possible, and please
report the bugs.



  • Prev by Date: Re: Re: Finding the periphery of a region
  • Next by Date: Re: radical equation once more!
  • Previous by thread: Re: Function of several variables
  • Next by thread: Deformed Matrix Product