[Date Index] [Thread Index] [Author Index]
Re: Stop on message?
Re: the recent "stop on message" discussion. The earlier-posted solution from StackExchange suggests adding the following to the top of a notebook: - - - - - - - - - - messageHandler = If[Last[#], Abort] & Internal`AddHandler["Message", messageHandler] (* The above will abort the computation whenever a message would be printed= . *) (* It can be turned off using*) (* Internal`RemoveHandler["Message", messageHandler] *) - - - - - - - - - - This helps, and seems to prevent a complete freeze, but it does not always terminate the evaluation immediately. The Abort call seems to wait for something to finish before stopping everything. >From prior experience, I knew that Interrupt works more quickly than Abort. I realize this seems a little bit illogical, but nevertheless, that is my observation: Interrupt gets you out of trouble instantly, while Abort often doesn't. I substituted Interrupt in the handler, with much better results, as follow= s: - - - - - - - - - - (* ----- proposed new version ----- *) messageHandler = If[Last[#], Interrupt] & Internal`AddHandler["Message", messageHandler] (* The above will immediately (!) put up an Abort dialog offering to *) (* end the evaluation whenever an enabled message is issued. *) (* It can be turned off using *) (* Internal`RemoveHandler["Message", messageHandler] *) - - - - - - - - - - This tiny enhancement to Mathematica has proved amazingly helpful, and I hope everyone will try it. It is a relief not to be always anticipating the next messy crash. Let me know if you have any additions or corrections. Ralph Dratman On Tue, May 29, 2012 at 5:47 AM, Szabolcs Horv=E1t <szhorvat at gmail.com> wro= te: > Please see here for a method that will reliably abort immediately when a > message is generated. > http://mathematica.stackexchange.com/questions/1512/how-to-abort-on-any-m= essage-generated