Mathematica Stack Exchange is a question and answer site for users of Mathematica. Join them; it only takes a minute:

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

Is there a simple, built-in way to retrieve the text of a message, given it's identifier (such as Power::infy)?

The documentation describes how Message does this: it looks for different language versions (Power::infy::langname), then it looks under the symbol name (Power::infy), then it looks under General (General::infy), then it uses $NewMessage ... it's pretty complicated.

Is there any built-in, hidden/undocumented way that will let me retrieve the text of a message in a simple way, without issuing the message?

I see two possibilities:

  1. Reimplement the whole lookup procedure. This is a lot of work.
  2. Implement a special stream and do something like Block[{$Messages = ...}, Message[symb::name]]. Also a lot of work (implementing the stream methods), and I'm not even sure it would work.

Or maybe there is an undocumented way. ?*`*Message* gives plenty of symbols, but it's not clear which may be interesting and what they do.

share|improve this question
up vote 14 down vote accepted

It is actually straightforward. You use Messages[symbol] to get the list, e.g.

Power::infy (* trigger loading the message *)
(* {HoldPattern[Power::infy] :> "Infinite expression `1` encountered."} *)

then, as it is a list of replacement rules, you can simply do

Power::infy /. Messages[Power]
(* "Infinite expression `1` encountered." *)

There is a bit of trickery going on here as messages are not loaded until they are used, so on a fresh kernel, Messages[symbol] will return an empty list. However, using it as a set of replacement rules is guaranteed to work because symbol::msg is evaluated first, triggering the loading process before Messages[symbol] is executed.

share|improve this answer
I said nothing, I was confused as to how all these works. Big +1 for making me learn something new – Rojo Feb 23 '13 at 14:44
@Rojo I learned something new, too, so it's a win for everybody. – rcollyer Feb 23 '13 at 14:47
@szabolcs it appears there is at least one case where running MessageName[sym, name] /. Messages[sym] does not work. And, no I don't understand why. – rcollyer Oct 18 '13 at 14:39

Your Answer


By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.