Confirm

Confirm[expr]

confirms that expr is not considered a failure, otherwise throwing an error to the nearest surrounding Enclose.

Confirm[expr,info]

evaluates info and includes its value in the thrown error if expr is not confirmed.

Confirm[expr,info,tag]

uses the specified tag for any thrown errors.

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 allclose all

Basic Examples  (2)

Confirm[expr] gives expr if expr is not considered a failure:

If Confirm encounters a failure, it stops evaluation and throws an error to the surrounding Enclose:

Define a function that propagates failures in its arguments:

Scope  (4)

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

info is only evaluated when expr cannot be confirmed:

Create a function that calls Confirm with a tag so that it can be caught dynamically:

If no tag is given, Confirm is lexically scoped:

Failures are wrapped in a Failure before they are thrown, unless they were thrown from another confirmation function:

This behavior is overruled when info is not Null:

Applications  (1)

Print a message when a failure is detected:

Properties & Relations  (1)

Confirm can be emulated with ConfirmBy:

Possible Issues  (3)

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

Untagged Confirm works by replacing instances of the symbol Confirm with a tagged variant:

Tagged Confirm requires an Enclose with a matching tag:

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

BibLaTeX

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