Confirm
Details
- Confirm[expr,…] returns expr if expr is successfully confirmed.
- Confirm[expr,…] considers expr a failure and throws an error if expr has any of the following forms:
-
Failure[…] Missing[…] $Failed $Canceled $Aborted - Confirm is dynamically scoped when given a tag. Otherwise, it is lexically scoped. »
- The default value of info is Null.
- expr is wrapped in a Failure before it is thrown unless info is Null and expr is a Failure from a previous confirmation function. »
- Failure objects generated by Confirm include the following fields:
-
"Information" info from Confirm[expr,info,…] "Expression" expr from Confirm[expr,…] - Values of these fields can be extracted using failure["prop"] or directly through Enclose[expr,"prop"].
Examples
open all close allBasic Examples (2)
Confirm[expr] gives expr if expr is not considered a failure:
Enclose[f[x, Confirm[y], z]]If Confirm encounters a failure, it stops evaluation and throws an error to the surrounding Enclose:
Enclose[f[x, Confirm[$Failed], z]]Define a function that propagates failures in its arguments:
addtwo[x_] := Enclose[Confirm[x] + 2]addtwo[4]addtwo[Missing[]]Scope (4)
Confirm stops evaluation and returns to the matching Enclose when it throws an error:
Enclose[Echo[1];Confirm[$Failed];Echo[2]]info is only evaluated when expr cannot be confirmed:
Enclose[Confirm[2, Echo["info was evaluated"]]]Enclose[Confirm[$Failed, Echo["info was evaluated"]]]Create a function that calls Confirm with a tag so that it can be caught dynamically:
f[x_] := g[3 + Confirm[x, Null, "fooTag"]]h[y_] := Enclose[f[y], Identity, "fooTag"]h[2]h[$Canceled]If no tag is given, Confirm is lexically scoped:
f2[x_] := g[3 + Confirm[x]]h2[y_] := Enclose[f2[y]]h2[2]Failures are wrapped in a Failure before they are thrown, unless they were thrown from another confirmation function:
Enclose[Confirm[Missing[]]]Enclose[Confirm[%]]This behavior is overruled when info is not Null:
Enclose[Confirm[%, "foo"]]Applications (1)
Print a message when a failure is detected:
mountainElevation::inv = "Could not interpret `` as a mountain.";mountainElevation[name_] :=
Enclose[
Confirm[Interpreter["Mountain"][name], Message[mountainElevation::inv, name]]["Elevation"],
$Failed&]mountainElevation["k2"]mountainElevation[π]Properties & Relations (1)
Possible Issues (3)
Confirm must be given a tag or be within a lexical Enclose:
Confirm[2]Untagged Confirm works by replacing instances of the symbol Confirm with a tagged variant:
Enclose[Hold[Confirm]]Tagged Confirm requires an Enclose with a matching tag:
Enclose[Confirm[$Failed, Null, "foo"], Identity, "bar"]See Also
Enclose ConfirmAssert ConfirmBy ConfirmMatch Failsafe Check FailureQ Throw
Function Repository: FailOnMessage SuccessfulQ
Related Guides
History
Text
Wolfram Research (2020), Confirm, Wolfram Language function, https://reference.wolfram.com/language/ref/Confirm.html.
CMS
Wolfram Language. 2020. "Confirm." Wolfram Language & System Documentation Center. Wolfram Research. https://reference.wolfram.com/language/ref/Confirm.html.
APA
Wolfram Language. (2020). Confirm. Wolfram Language & System Documentation Center. Retrieved from https://reference.wolfram.com/language/ref/Confirm.html
BibTeX
@misc{reference.wolfram_2026_confirm, author="Wolfram Research", title="{Confirm}", year="2020", howpublished="\url{https://reference.wolfram.com/language/ref/Confirm.html}", note=[Accessed: 13-June-2026]}
BibLaTeX
@online{reference.wolfram_2026_confirm, organization={Wolfram Research}, title={Confirm}, year={2020}, url={https://reference.wolfram.com/language/ref/Confirm.html}, note=[Accessed: 13-June-2026]}