Mathematica 9 is now available
Services & Resources / Wolfram Forums
-----
 /
MathGroup Archive
2006
*January
*February
*March
*April
*May
*June
*July
*August
*September
*October
*November
*December
*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

Re: To: Omega Consulting, Problem with $AbortMessage trap (The Mathematica Journal).

  • To: mathgroup at smc.vnet.net
  • Subject: [mg70990] Re: [mg70976] To: Omega Consulting, Problem with $AbortMessage trap (The Mathematica Journal).
  • From: Carl Woll <carlw at wolfram.com>
  • Date: Sat, 4 Nov 2006 04:07:59 -0500 (EST)
  • References: <200611030639.BAA21017@smc.vnet.net>

Philipp wrote:

>I've been working on an extension to your solution of immediate
>interception of Message[] to make it sensitive only to specified
>messages (analogous to the Check[]).
>
>But this aside, I have encountered a curious behaviour of your original
>solution, namely
>
>In[]:=   Unprotect[Message];
>         Message[args___] :=
>          (Block[{$AbortMessageQ = False}, Message[args]]; Abort[]) /;
>             $AbortMessageQ
>         Protect[Message];
>
>
>In[]:=   $AbortMessageQ = False;
>
>
>In[]:=   (Log[1, 1]; Prime[-120]; StringLength[ToString[N[Pi, 10^5]]])
>
>         General::"dbyz": "Division by zero."
>
>         \[Infinity]::"indet": "Indeterminate expression
>           0 ComplexInfinity encountered."
>
>         Prime::"intpp": "Positive integer argument expected
>           in Prime[-120]."
>
>Out[]:= 100001
>
>Now setting he control variable to True
>
>In[]:=   $AbortMessageQ = True;
>
>gives the expected result, i.e.,
>
>         General::"dbyz": "Division by zero."
>
>Out[]:=  $Aborted
>
>However, using Off[] to turn off the first message,
>
>In[]:=   Off[General::"dbyz"]
>
>In[]:=   (Log[1, 1]; Prime[-120]; StringLength[ToString[N[Pi, 10^5]]])
>Out[]:=  $Aborted
>
>fails to print the message.
>
>Could you please explain such a curious behaviour, and maybe provide a
>remedy?
>
>Cheers,
>Philip
>  
>
You need to add another condition to your Message redefinition:

Unprotect[Message];
Message[args___] := Block[{$AbortMessageQ = False},
    Message[args]; Abort[]
] /; $AbortMessageQ && !MatchQ[{args}, {$Off[], ___}]
Protect[Message];

This way we don't abort on messages that have been turned off.

Carl Woll
Wolfram Research


  • Prev by Date: Re: Re: Publicon
  • Next by Date: Assuming non-integer values in Mathematica simplifications
  • Previous by thread: To: Omega Consulting, Problem with $AbortMessage trap (The Mathematica Journal).
  • Next by thread: Re: Mathematica / MacOSX / XDarwin fonts problem