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$– dionysSep 19, 2015 at 14:09
-
$\begingroup$ Seems I didn't scroll down to the essential information. $\endgroup$– highsciguySep 19, 2015 at 14:17
1 Answer
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