MathGroup Archive 2006

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

Search the Archive

(Revisited) Intercepting and Controlling Mathematica Exceptions.

  • To: mathgroup at smc.vnet.net
  • Subject: [mg72106] (Revisited) Intercepting and Controlling Mathematica Exceptions.
  • From: "Philipp" <Philipp.M.O at gmail.com>
  • 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
http://groups.google.co.uk/group/comp.soft-sys.math.mathematica/browse_frm/thread/93ec51324d209913/ae474fbeb55c4105#ae474fbeb55c4105
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

Begin["System`"]

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

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

"\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;
    Clear[Message];
   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.

Cheers,

Philipp.


  • 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