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.

更多信息

  • 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.

范例

打开所有单元关闭所有单元

基本范例  (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 语言函数,https://reference.wolfram.com/language/ref/Confirm.html.

文本

Wolfram Research (2020),Confirm,Wolfram 语言函数,https://reference.wolfram.com/language/ref/Confirm.html.

CMS

Wolfram 语言. 2020. "Confirm." Wolfram 语言与系统参考资料中心. Wolfram Research. https://reference.wolfram.com/language/ref/Confirm.html.

APA

Wolfram 语言. (2020). Confirm. Wolfram 语言与系统参考资料中心. 追溯自 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: 02-January-2025 ]}

BibLaTeX

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