1
$\begingroup$

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.

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

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];
  $Failed);

MyFunction[10]

1

MyFunction["abc"]

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

| improve this answer | |
$\endgroup$

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