Check

Check[expr, failexpr]
evaluates expr, and returns the result, unless messages were generated, in which case it evaluates and returns failexpr.

Check[expr, failexpr, {s1::t1, s2::t2, ...}]
checks only for the specified messages.

Check[expr, failexpr, "name"]
checks only for messages in the named message group.

DetailsDetails

  • Check has attribute HoldAll.
  • Check does not test for messages that have been switched off using Off, or by uses of Quiet that occur inside it.
  • The operation of Check is not affected by being enclosed inside Quiet.
  • In Check[expr, failexrp, "name"], possible named message groups are given by $MessageGroups.
  • Explicit message names of the form can be mixed with named message groups.

ExamplesExamplesopen allclose all

Basic Examples (2)Basic Examples (2)

Return err when a message is generated:

In[1]:=
Click for copyable input
Out[1]=
In[2]:=
Click for copyable input
Out[2]=

Check only for specific messages:

In[1]:=
Click for copyable input
Out[1]=
In[2]:=
Click for copyable input
Out[2]=
New in 1 | Last modified in 7
New to Mathematica? Find your learning path »
Have a question? Ask support »