Confirm

Confirm[expr]

confirms that expr does not represent an error, otherwise throwing a Failure to the nearest lexically surrounding Enclose.

Confirm[expr,info]

if expr represents an error, evaluates info and includes the result in the thrown Failure.

Confirm[expr,info,tag]

uses the specified tag for any thrown errors.

Details

  • expr is considered an error if it is $Canceled or satisfies MissingQ or FailureQ.
  • expr is returned unchanged if it does not represent an error.
  • The default value of info is Null.
  • Generally, if expr represents an error then it is wrapped in a Failure before it is thrown. However, if expr has head Failure with tag "ConfirmationFailed", and no info has been provided, Confirm will throw expr without wrapping it in another Failure.

Examples

open allclose all

Basic Examples  (2)

Confirm that a expression doesn't represent an error, stopping evaluation if it does:

Create a function that propagates errors in its arguments:

Scope  (3)

Confirm stops evaluation and returns to the matching Enclose when it throws an error:

Create a function that calls Confirm with a tag so that it can be caught by an enclosing function:

Errors are wrapped in Failure before they are thrown, unless they came from another call to a confirmation function:

This behavior is overruled when info is provided:

Applications  (1)

Print a message when a confirmation fails:

Possible Issues  (1)

Confirm must be given a tag, or be within a lexical Enclose:

Wolfram Research (2020), Confirm, Wolfram Language function, https://reference.wolfram.com/language/ref/Confirm.html.

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_2023_confirm, author="Wolfram Research", title="{Confirm}", year="2020", howpublished="\url{https://reference.wolfram.com/language/ref/Confirm.html}", note=[Accessed: 13-April-2024 ]}

BibLaTeX

@online{reference.wolfram_2023_confirm, organization={Wolfram Research}, title={Confirm}, year={2020}, url={https://reference.wolfram.com/language/ref/Confirm.html}, note=[Accessed: 13-April-2024 ]}