I would like to print a warning/error message from my own module. Of course I could use Print["WARNING: my warning"] but in all the output this would be barely visible. Ideally my user defined message would appear in the same style as those produced by Mathematica built-in functions.

  • 1
    $\begingroup$ This is covered well in the documentation here: Messages. $\endgroup$
    – dionys
    Commented Sep 19, 2015 at 14:09
  • $\begingroup$ Seems I didn't scroll down to the essential information. $\endgroup$
    – highsciguy
    Commented Sep 19, 2015 at 14:17

1 Answer 1


You can do this using Mathematica's built-in message system; also, I'd suggest looking through Mathematica's package development documentation and tutorials, as these commonly go hand-in-hand; here is one starting place.

As for the specific question, here is an example:

MyFunction::argerr = "Bad argument given to MyFunction: `1`";
MyFunction[x_Integer] := Mod[x^2, x+1];
MyFunction[x_] := (
  Message[MyFunction::argerr, x];




MyFunction::argerr: Bad argument given to MyFunction: abc


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