8

I'm using NonLinearModelFit on a large set of data and which contains a nested Do-loop. I'd like to see all of the cases where there is an issue with the non-linear model fit, but after about five of these messages, further warnings are suppressed. Is there some way to make sure it doesn't suppress these messages after repeated warnings along the way?

z = NonlinearModelFit[trimspectra, a (x/x0)^(-b + c (Log[x/x0])), {a, b, c}, x];
m_goldberg
  • 107,779
  • 16
  • 103
  • 257
Tom Mozdzen
  • 521
  • 5
  • 16
  • 7
    From the docs on Message: Off[General::stop] makes the Wolfram Language not stop repeating messages. -- You might also be interested in Check. It can respond to messages even though the printing has stopped. -- Also perhaps of interest to you: http://mathematica.stackexchange.com/questions/20367/how-to-catch-complete-error-message-information – Michael E2 Mar 09 '16 at 20:25
  • Yes, Thank you Michael, Message: Off[General::stop] did the trick. When I get a message, is there a simple way to print out a variable to tell me where in the do-loop the issue occurred? Such as If[MessageList[-1]!={}, Print["Variable = ", variableOfInterest] ] ? – Tom Mozdzen Mar 11 '16 at 21:39
  • I just tried the If statement inside the loop. Outside the loop, it printed in a test case, but inside the loop, no printing. NonlinearModelFit::sszero: is my error warning. z = NonlinearModelFit[trimspectra, a (x/x0)^-b, {a, b}, x]; If[MessageList[-1] != {}, Print["LST = ", lst]]; – Tom Mozdzen Mar 11 '16 at 21:48
  • 1
    The Q I linked to has a good method. See my answer below. – Michael E2 Mar 11 '16 at 21:54

1 Answers1

6

From Szabolcs's answer to How to catch complete error message information, including the message text as it would be printed?:

report[m_] := If[NumericQ[i], Print[HoldForm[i] == i]];
Internal`AddHandler["Message", report];
Off[General::stop];

Do[
 1/Mod[i, 3],
 {i, 15}]

On[General::stop];
Internal`RemoveHandler["Message", report]

Mathematica graphics

One can also do the following if you know where the error might occur:

Do[
 Check[1/Mod[i, 3], Print[HoldForm[i] == i]],
 {i, 15}]

Mathematica graphics

Michael E2
  • 235,386
  • 17
  • 334
  • 747