Basic Examples (6)
Print a generic error message and return a Failure object:
Specify the message text:
Specify a tag:
Choose a generic message based on the given tag:
Use Message syntax:
Use Failure syntax:
Scope (2)
Include additional metadata:
Specify a different message symbol:
Options (8)
Verbose (2)
By default, only a small number of keys are included in the Failure object:
Use "Verbose"→True to include additional metadata used internally by MessageFailure:
Stack (3)
Include a stack trace in the failure metadata:
View the stack trace:
Include a more detailed stack trace in the failure metadata:
View the stack trace:
Use StackComplete for even more detail:
When using the option setting "Verbose"→True, the stack will also include evaluations made by MessageFailure as well:
The stack trace now includes internal evaluations of MessageFailure as well:
Applications (4)
Create directives for defining new functions:
Define a new function using these directives:
Test the function:
Undefined inputs are automatically caught as an error:
Properties and Relations (6)
The message can be retrieved from the Failure object:
A message can be reissued from the Failure object using Message:
MessageFailure can also reissue the message from the Failure:
MessageFailure can use modern template specifications:
Compare to Message:
Message templates need not be strings:
MessageFailure can print messages for Failure objects that use named template parameters:
Compare to Message:
Messages with named template slots are temporarily redefined to avoid giving unsupported templates to Message:
Use a message handler to print the current message definition at the time of message generation:
MySymbol::testing"The parameter appears here: \!\(\*RowBox[{\"123\"}]\)"MySymbol::testing The original message definition is restored:
Possible Issues (2)
Using named template slots or template expressions in message definitions gives a template that is not supported by Message:
Use MessageFailure to issue these kinds of messages instead:
Non-string templates won't appear formatted in the resulting Failure object:
The printed message cannot be retrieved from the failure either: