Re: Aborting execution on first message
- To: mathgroup at smc.vnet.net
- Subject: [mg115334] Re: Aborting execution on first message
- From: Maxim <m.r at inbox.ru>
- Date: Sat, 8 Jan 2011 03:36:55 -0500 (EST)
- References: <ig0br0$sa1$1@smc.vnet.net>
On Jan 4, 5:52 pm, Yaroslav Bulatov <yarosla... at gmail.com> wrote:
> Is there a way to Abort execution on the first message generated?
> Essentially, I'm looking to mimic behavior of "Break at Message" of
> the Debugger in normal mode
There is an undocumented way:
Internal`HandlerBlock[
{"Message", Replace[#, _[_, True] :> Abort[]] &},
Do[Print[i/0], {i, 5}]]
Another handler type is "MessageTextFilter". "Message" is invoked for
every generated message and passes one argument of the form
Hold[..., ...] to the handler function, with the second element set to
False for quieted messages. "MessageTextFilter" is invoked for
messages that actually get printed and calls the function with three
arguments.
Maxim Rytin
m.r at inbox.ru