# How to stop Mathematica from turning off warning messages in a loop?

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];

• 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: mathematica.stackexchange.com/questions/20367/… Commented Mar 9, 2016 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] ] ? Commented Mar 11, 2016 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]]; Commented Mar 11, 2016 at 21:48
• The Q I linked to has a good method. See my answer below. Commented Mar 11, 2016 at 21:54

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

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

On[General::stop];
InternalRemoveHandler["Message", report]


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}]


• Thanks again - the last section did it for me, but the 1st two sections are helpful in general for when I'd like to collect the messages. (-: Commented Mar 11, 2016 at 22:09
• @Szabolcs Sorry! Commented Mar 11, 2016 at 22:15
• @MichaelE2 Don't worry about it, I know the spelling looks very strange :-) Commented Mar 13, 2016 at 10:16
• Is there an easy modification to avoid the suppression of a specific error message? For example DeleteFile::fdnfnd. Commented Dec 19, 2022 at 15:18