Skip to main content
added 601 characters in body
Source Link
Carl Woll
  • 132.7k
  • 6
  • 253
  • 366

Updated to issue a General::stop message

Maybe the following does what you want?

handler[Hold[Message[Test::message], True]] := With[ {stop = Flatten@Position[$MessageList, HoldForm[General::stop]]}, Which[ FreeQ[$MessageList[[stop-1]], HoldForm[Test::message]], CellPrint @ Cell[ BoxData[Internal`MessageTemplate[Test, "message", "Test message", StandardForm]], "Message","MSG" ]; If[Count[$MessageList, HoldForm[Test::message]] > 2,  CellPrint @ Cell[ BoxData[Internal`MessageTemplate[Test BoxData[Internal`MessageTemplate[General, "message""stop", "TestStringForm[General::stop, message"HoldForm[Test::message]], StandardForm]],   "Message", "MSG" ] ] ] ] test[x_] := If[1<x<2, Message[Test::message];x^2, x]; Internal`HandlerBlock[{"Message", handler}, NIntegrate[test[x], {x,0,3}]] 

Test::message: Test message

5.33333

Maybe the following does what you want?

handler[Hold[Message[Test::message], True]] := CellPrint @ Cell[ BoxData[Internal`MessageTemplate[Test, "message", "Test message", StandardForm]], "Message","MSG" ] test[x_] := If[1<x<2, Message[Test::message];x^2, x]; Internal`HandlerBlock[{"Message", handler}, NIntegrate[test[x], {x,0,3}]] 

Test::message: Test message

5.33333

Updated to issue a General::stop message

Maybe the following does what you want?

handler[Hold[Message[Test::message], True]] := With[ {stop = Flatten@Position[$MessageList, HoldForm[General::stop]]}, Which[ FreeQ[$MessageList[[stop-1]], HoldForm[Test::message]], CellPrint @ Cell[ BoxData[Internal`MessageTemplate[Test, "message", "Test message", StandardForm]], "Message","MSG" ]; If[Count[$MessageList, HoldForm[Test::message]] > 2,  CellPrint @ Cell[  BoxData[Internal`MessageTemplate[General, "stop", StringForm[General::stop, HoldForm[Test::message]], StandardForm]],   "Message", "MSG" ] ] ] ] test[x_] := If[1<x<2, Message[Test::message];x^2, x]; Internal`HandlerBlock[{"Message", handler}, NIntegrate[test[x], {x,0,3}]] 

Test::message: Test message

5.33333

Source Link
Carl Woll
  • 132.7k
  • 6
  • 253
  • 366

Maybe the following does what you want?

handler[Hold[Message[Test::message], True]] := CellPrint @ Cell[ BoxData[Internal`MessageTemplate[Test, "message", "Test message", StandardForm]], "Message","MSG" ] test[x_] := If[1<x<2, Message[Test::message];x^2, x]; Internal`HandlerBlock[{"Message", handler}, NIntegrate[test[x], {x,0,3}]] 

Test::message: Test message

5.33333