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.
Asked
Active
Viewed 2,907 times
1
Michael E2
- 235,386
- 17
- 334
- 747
highsciguy
- 1,700
- 1
- 16
- 23
-
1This is covered well in the documentation here: Messages. – dionys Sep 19 '15 at 14:09
-
Seems I didn't scroll down to the essential information. – highsciguy Sep 19 '15 at 14:17
1 Answers
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];
$Failed);
MyFunction[10]
1
MyFunction["abc"]
MyFunction::argerr: Bad argument given to MyFunction: abc
$Failed
nben
- 2,148
- 9
- 20