Set Up Error Checking and Messages in a Function

Use the same error-messaging mechanism in your functions that system functions use.

Define a function that issues an error message

Define a function that returns a string of n asterisks, with n limited to 80. If n is too large, issue a message and limit the length to 80:

  • Message names always consist of a function name and message identifier separated by a double colon (::).

Define the message

Define the message, with a placeholder for the message argument:

  • Messages can have more than one argument or no arguments at all.

Test the function

No message:

Error message:

Notes

Messages gives a list of the messages associated with a function:
Use Quiet to suppress messages: