ConfirmMatch[expr,form]
confirms that expr matches the pattern form, otherwise throwing a Failure to the nearest lexically surrounding Enclose.
ConfirmMatch[expr,form,info]
if expr does not match form, evaluates info and includes the result in the thrown Failure.
ConfirmMatch[expr,form,info,tag]
uses the tag tag for any thrown errors.
ConfirmMatch
ConfirmMatch[expr,form]
confirms that expr matches the pattern form, otherwise throwing a Failure to the nearest lexically surrounding Enclose.
ConfirmMatch[expr,form,info]
if expr does not match form, evaluates info and includes the result in the thrown Failure.
ConfirmMatch[expr,form,info,tag]
uses the tag tag for any thrown errors.
Details
- expr is returned unchanged if it does not represent a error.
- The default value of info is Null.
Examples
Basic Examples (2)
Confirm that a expression matches a pattern, stopping evaluation if it does:
Enclose[f[ConfirmMatch[2, _Integer]]]Enclose[f[ConfirmMatch[4.5, _Integer]]]Create a function that throws an error when given an unexpected input:
getPopulation[e_] := Enclose[ConfirmMatch[e, _Entity]["Population"]]getPopulation[Entity["City", {"Boston", "Massachusetts", "UnitedStates"}]]getPopulation["narnia"]Related Guides
Text
Wolfram Research (2020), ConfirmMatch, Wolfram Language function, https://reference.wolfram.com/language/ref/ConfirmMatch.html.
CMS
Wolfram Language. 2020. "ConfirmMatch." Wolfram Language & System Documentation Center. Wolfram Research. https://reference.wolfram.com/language/ref/ConfirmMatch.html.
APA
Wolfram Language. (2020). ConfirmMatch. Wolfram Language & System Documentation Center. Retrieved from https://reference.wolfram.com/language/ref/ConfirmMatch.html
BibTeX
@misc{reference.wolfram_2026_confirmmatch, author="Wolfram Research", title="{ConfirmMatch}", year="2020", howpublished="\url{https://reference.wolfram.com/language/ref/ConfirmMatch.html}", note=[Accessed: 23-June-2026]}
BibLaTeX
@online{reference.wolfram_2026_confirmmatch, organization={Wolfram Research}, title={ConfirmMatch}, year={2020}, url={https://reference.wolfram.com/language/ref/ConfirmMatch.html}, note=[Accessed: 23-June-2026]}