If I evaluate this expression:
Module[{}, 1/0;0^0]; msg = $MessageList
I get:
"Power::infy: Infinite expression 1/0 encountered. >>"
"Power::indet: Indeterminate expression 0^0 encountered. >>"
{Power::infy,mrtError::function}
How can I collect the complete error messages in msg
, instead of just the first part? Something for msg
like:
{"Power::infy: Infinite expression 1/0 encountered. >>"
,"Power::indet: Indeterminate expression 0^0 encountered. >>"}
Some clue?
Answer
Update See here for a documented way to do the very same thing in v10.0 or later.
This method will only catch those messages which would actually get printed, not those which are Quiet
ed or turned Off
.
We can use handlers:
messages = {}
clearMessages[] := messages = {}
collectMessages[m_] := AppendTo[messages, m]
Internal`AddHandler["Message", collectMessages]
Then do
clearMessages[]
1/0; 0/0;
messages
Internal`RemoveHandler["Message", collectMessages]
Reference and details: How to abort on any message generated?
Comments
Post a Comment