Wolfram Function Repository
Instant-use add-on functions for the Wolfram Language
Function Repository Resource:
Stop an evaluation when a message is encountered and return a given failure expression
ResourceFunction["FailOnMessage"][eval] stops evaluation of eval if a message occurs and returns $Failed. | |
ResourceFunction["FailOnMessage"][eval,default] stops evaluation of eval if a message occurs and returns default. | |
ResourceFunction["FailOnMessage"][eval,default,quiet] stops evaluation of eval if a message occurs and returns default while ignoring messages in quiet. | |
ResourceFunction["FailOnMessage"][eval,default,quiet,listen] stops evaluation of eval if any message in listen occurs,even if quieted. |
Return $Failed if a message occurs:
In[1]:= |
|
Out[1]= |
|
Give a different failure expression:
In[2]:= |
|
Out[2]= |
|
Ignore some messages:
In[3]:= |
|
Out[3]= |
|
Fail on some messages even if quieted:
In[4]:= |
|
Out[4]= |
|
Some evaluations can trigger a large number of messages:
In[5]:= |
|
Out[5]= |
|
Check can be used to return a different expression if a message occurs, but the full evaluation still takes place:
In[6]:= |
|
Out[6]= |
|
Use FailOnMessage to stop immediately upon encountering a message:
In[7]:= |
|
Out[7]= |
|
When nested, the outermost FailOnMessage takes precedence:
In[8]:= |
|
Out[8]= |
|
Wolfram Language 11.3 (March 2018) or above
This work is licensed under a Creative Commons Attribution 4.0 International License