Wolfram Function Repository
Instant-use add-on functions for the Wolfram Language
Function Repository Resource:
Print a message and return a failure object
ResourceFunction["MessageFailure"]["tag","message"] uses "tag" as the Failure tag. | |
ResourceFunction["MessageFailure"]["tag",<|…|>] determines the message text and failure details from the given Association. | |
ResourceFunction["MessageFailure"][symbol::tag] prints the message symbol::tag and returns a corresponding Failure object. | |
ResourceFunction["MessageFailure"][symbol::tag,e1,e2] prints a message and returns a Failure, inserting the values of the ei as needed. |
"MessageTemplate" | a string template for a message |
"MessageParameters" | parameters to use for the message template |
Print a generic error message and return a Failure object:
In[1]:= |
Out[1]= |
Specify the message text:
In[2]:= |
Out[2]= |
Specify a tag:
In[3]:= |
Out[3]= |
Choose a generic message based on the given tag:
In[4]:= |
Out[4]= |
Use Message syntax:
In[5]:= |
Out[5]= |
In[6]:= |
Out[6]= |
Use Failure syntax:
In[7]:= |
Out[7]= |
In[8]:= |
Out[8]= |
Include additional metadata:
In[9]:= |
Out[9]= |
Specify a different message symbol:
In[10]:= |
Out[10]= |
Use a custom message function:
In[11]:= |
Out[11]= |
Issue the message with ResourceFunctionMessage instead of Message:
In[12]:= |
Out[12]= |
Define a function that uses the default setting "MessageFunction"→Automatic:
In[13]:= |
By default, Message will be used:
In[14]:= |
Out[14]= |
Once converted to a resource function, ResourceFunctionMessage will be automatically used instead:
In[15]:= |
Out[15]= |
In[16]:= |
Out[16]= |
Use SetOptions to change this globally:
In[17]:= |
Out[17]= |
In[18]:= |
Out[18]= |
Restore the default setting:
In[19]:= |
By default, only a small number of keys are included in the Failure object:
In[20]:= |
Out[20]= |
In[21]:= |
Out[21]= |
Use "Verbose"→True to include additional metadata used internally by MessageFailure:
In[22]:= |
Out[22]= |
In[23]:= |
Out[23]= |
Include a stack trace in the failure metadata:
In[24]:= |
In[25]:= |
Out[25]= |
View the stack trace:
In[26]:= |
Out[26]= |
Include a more detailed stack trace in the failure metadata:
In[27]:= |
In[28]:= |
Out[28]= |
View the stack trace:
In[29]:= |
Out[29]= |
Use StackComplete for even more detail:
In[30]:= |
Out[30]= |
In[31]:= |
Out[31]= |
When using the option setting "Verbose"→True, the stack will also include evaluations made by MessageFailure as well:
In[32]:= |
In[33]:= |
Out[33]= |
The stack trace now includes internal evaluations of MessageFailure as well:
In[34]:= |
Out[34]= |
Create directives for defining new functions:
In[35]:= |
In[36]:= |
Define a new function using these directives:
In[37]:= |
Test the function:
In[38]:= |
Out[38]= |
In[39]:= |
Out[39]= |
Undefined inputs are automatically caught as an error:
In[40]:= |
Out[40]= |
The message can be retrieved from the Failure object:
In[41]:= |
Out[41]= |
In[42]:= |
Out[42]= |
A message can be reissued from the Failure object using Message:
In[43]:= |
In[44]:= |
Out[44]= |
In[45]:= |
MessageFailure can also reissue the message from the Failure:
In[46]:= |
Out[46]= |
MessageFailure can use modern template specifications:
In[47]:= |
In[48]:= |
Out[48]= |
Compare to Message:
In[49]:= |
Message templates need not be strings:
In[50]:= |
MessageFailure can print messages for Failure objects that use named template parameters:
In[51]:= |
Out[51]= |
In[52]:= |
Out[52]= |
Compare to Message:
In[53]:= |
Out[53]= |
Messages with named template slots are temporarily redefined to avoid giving unsupported templates to Message:
In[54]:= |
In[55]:= |
Out[55]= |
Use a message handler to print the current message definition at the time of message generation:
In[56]:= |
Out[56]= |
The original message definition is restored:
In[57]:= |
Out[57]= |
Using named template slots or template expressions in message definitions gives a template that is not supported by Message:
In[58]:= |
In[59]:= |
Use MessageFailure to issue these kinds of messages instead:
In[60]:= |
Out[60]= |
Non-string templates won't appear formatted in the resulting Failure object:
In[61]:= |
Out[61]= |
The printed message cannot be retrieved from the failure either:
In[62]:= |
Out[62]= |
This work is licensed under a Creative Commons Attribution 4.0 International License