Possible Duplicate:
Best practices in error reporting (Mathematica)
Assume that I have a function
func[xNumber_,str_,listOfReals_]:=Module[{},
....
]
and I want to test that the user gave input expressions of the correct type. I know I can do something like xNumber_?NumberQ but then I don’t seem to find how to generate some informative error message. Therefore, currently, in the the module’s code I inserts If‘s where I test the arguments’ types and in case test fails I print some message and return False.
What should be considered smarter/more canonical/better practices to achieve this?
Built-in function
Messageis what you need. The following example is from the documentation.First define a function that issues an error message and returns unevaluated upon error
Next, define the message
With correct input the function evaluates as defined
returns
1.5. But, with incorrect input, you get