I have some global options that determine which messages are shown and which are not, e.g.

$MessagesShown = {Power::infy};
$MessagesNotShown = All;

Now the first line below will generate a message, while the second will not.

Quiet[1/0, Evaluate@$MessagesNotShown, Evaluate@$MessagesShown]
Quiet[0 Infinity, Evaluate@$MessagesNotShown, Evaluate@$MessagesShown]

This does not work however for messages that take an argument. For instance,

Quiet[Do[1/0,{5}], Evaluate@$MessagesNotShown, Evaluate@$MessagesShown]

The first will display the Power::infy message 3 times and then the General::stop message, while the second only displays the Power::infy message 3 times.

Say we do want to see the General::stop message (and many other messages are generated as well so simply not using Quiet is not an option), we would change:


But now the code above gives the error message Quiet::mgre, saying that the message General::stop was not resolved to a list of messages of the form symbol::name or symbol::name::language.

How do I do this? Is there a different syntax for messages with an argument?

  • $\begingroup$ The problem is that General::stop evaluates to a string. You will have to use Inactive or some type of hold gymnastics to prevent that. $\endgroup$ – Carl Woll Nov 6 '18 at 17:17
  • $\begingroup$ @CarlWoll I see, is there any reason why messages with arguments evaluate to a string but messages without do not? I guess this means it is impossible to do with $MessagesShown = {General::stop};, or even with $MessagesShown := {General::stop};, it would really have to be something like $MessagesShown = Inactive[Message][General,"stop"];? That is unfortunate.. $\endgroup$ – Jansen Nov 6 '18 at 17:58
  • $\begingroup$ Basically, all General messages evaluate to a string, it's not just messages with arguments. Any non-General messages that don't refer to a General message also evaluate to a string. It is only non-General messages that refer to a General message that don't evaluate, e.g., Power::infy uses General::infy, and so it doesn't evaluate. $\endgroup$ – Carl Woll Nov 6 '18 at 18:04
  • $\begingroup$ @CarlWoll I see, thanks. Then I think the simplest workaround is to define Attributes[myQuiet]={HoldFirst}; myQuiet[expr_,Hold[quietMsgs_],Hold[shownMsgs_]]=Quiet[expr,quietMsgs,shownMsgs] and then define e.g. $MessagesShown=Hold[{Power::infy,General::stop}];. $\endgroup$ – Jansen Nov 6 '18 at 18:20

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Browse other questions tagged or ask your own question.