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.
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.
Details
- 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,failexpr,"name"], possible named message groups are given by $MessageGroups.
- Explicit message names of the form s::t can be mixed with named message groups.
Examples
open all close allBasic Examples (2)
Scope (3)
Check for a message from a specific function:
Check[0 ^ 0, "message issued", Power::indet]The ArcTan::indet is not caught by Check:
Check[ArcTan[0, 0], "message issued", Power::indet]Use the head General to catch the message from any function:
Check[ArcTan[0, 0], "message issued", General::indet]Check[Sin[0 ^ 0], err, {General::infy, General::indet, General::argx}]Check[1 / 0, err, {General::infy, General::indet, General::argx}]Check for a message from a named group:
f = Compile[{{x, _Real}}, x]Check[f[I], "message issued", "Compiler"]Check[f[I], "message issued", "Graphics"]Applications (1)
Use Check and Quiet to provide values for arguments where a function is not applicable:
f[x_] := Quiet[Check[StringTake[x, 4], x, StringTake::take], StringTake::take]This function simply returns its argument if its argument is a string of length less than four:
f /@ {"abcdef", "ab", "eg3j"}Without the Check and Quiet, the middle input would have returned unevaluated with a message:
StringTake["ab", 4]Properties & Relations (3)
Check does not prevent messages from being issued:
Check[Sin[x, y], "too many", General::argx]Check does not detect messages suppressed with a inner Quiet:
Check[Quiet[1 / 0], error]However, the operation of Check is not affected by being inside Quiet:
Quiet[Check[1 / 0, error]]Check does not report messages that have been turned off:
Off[Power::infy]Check[1 / 0, "message issued"]On[Power::infy]Possible Issues (1)
A nested Check does not silence a message for an enclosing Check:
Check[Check[1 / 0, inner, Power::infy], outer, Power::infy]Use an intermediate Quiet to prevent the enclosing Check from reacting to the message:
Check[Quiet[Check[1 / 0, inner, Power::infy], Power::infy], outer, Power::infy]See Also
Catch ConfirmQuiet Failsafe MessageList $MessageList Message Quiet $MessageGroups Indeterminate TimeConstrained CheckAbort Assert
Function Repository: QuietCheck CheckReturn AbortOnMessage MessagedQ FailOnMessage
Tech Notes
Related Guides
Related Workflows
- Suppress Error Messages ▪
- Set Up Error Checking and Messages in a Function ▪
- Understand Error Messages
History
Introduced in 1988 (1.0) | Updated in 2007 (6.0) ▪ 2008 (7.0)
Text
Wolfram Research (1988), Check, Wolfram Language function, https://reference.wolfram.com/language/ref/Check.html (updated 2008).
CMS
Wolfram Language. 1988. "Check." Wolfram Language & System Documentation Center. Wolfram Research. Last Modified 2008. https://reference.wolfram.com/language/ref/Check.html.
APA
Wolfram Language. (1988). Check. Wolfram Language & System Documentation Center. Retrieved from https://reference.wolfram.com/language/ref/Check.html
BibTeX
@misc{reference.wolfram_2026_check, author="Wolfram Research", title="{Check}", year="2008", howpublished="\url{https://reference.wolfram.com/language/ref/Check.html}", note=[Accessed: 12-June-2026]}
BibLaTeX
@online{reference.wolfram_2026_check, organization={Wolfram Research}, title={Check}, year={2008}, url={https://reference.wolfram.com/language/ref/Check.html}, note=[Accessed: 12-June-2026]}