ConfirmAssert
ConfirmAssert[test]
confirms that test is True, otherwise throwing an error to the nearest surrounding Enclose.
ConfirmAssert[test,info]
evaluates info and includes its value in the thrown error if test is not True.
ConfirmAssert[test,info,tag]
uses the specified tag for any thrown errors.
Details

- ConfirmAssert[…] always returns Null.
- ConfirmAssert is dynamically scoped when given a tag. Otherwise, it is lexically scoped. »
- The default value of info is Null.
- Failure objects generated by ConfirmAssert include the following fields:
-
"Information" info from ConfirmAssert[test,info,…] "Test" expr from ConfirmAssert[test,…] - Values of these fields can be extracted using failure["prop"] or directly through Enclose[expr,"prop"].
Examples
open allclose allBasic Examples (2)
Confirm that an assertion is true:
If the assertion fails, stop evaluation and throw an error to the surrounding Enclose:
Scope (3)
ConfirmAssert 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 ConfirmAssert with a tag so that it can be caught dynamically:
If no tag is given, ConfirmAssert is lexically scoped:


Properties & Relations (2)
ConfirmAssert can be emulated with ConfirmBy or ConfirmMatch:
ConfirmAssert[f[expr]] is effectively equivalent to ConfirmBy[expr,f] except that it returns Null instead of expr:
Possible Issues (3)
ConfirmAssert must be given a tag or be within a lexical Enclose:

Untagged ConfirmAssert works by replacing instances of the symbol ConfirmAssert with a tagged variant:
Tagged ConfirmAssert requires an Enclose with a matching tag:

Text
Wolfram Research (2020), ConfirmAssert, Wolfram Language function, https://reference.wolfram.com/language/ref/ConfirmAssert.html.
CMS
Wolfram Language. 2020. "ConfirmAssert." Wolfram Language & System Documentation Center. Wolfram Research. https://reference.wolfram.com/language/ref/ConfirmAssert.html.
APA
Wolfram Language. (2020). ConfirmAssert. Wolfram Language & System Documentation Center. Retrieved from https://reference.wolfram.com/language/ref/ConfirmAssert.html