Enclose
Enclose[expr,f]
returns f[err] for the caught error err.
Enclose[expr,f,tag]
only catches errors generated with a tag matching tag.
Details

- Enclose[expr,…] returns the value of expr if no error was caught during its evaluation. »
- Enclose will not catch errors that have already been caught by an inner Enclose.
- When no tag is provided, Enclose will add tags to all untagged lexically contained confirmation functions. »
- tag can be any expression including a pattern.
- Catches errors thrown by Confirm, ConfirmBy, ConfirmMatch, ConfirmQuiet, and ConfirmAssert.
- Enclose effectively calls Catch with a special tag.
- The default value of f is Identity.
- If f is a string, err[f] will be returned instead of f[err]. »
Examples
open allclose allBasic Examples (2)
Scope (6)
Process an error before returning:
Set f to "Expression" to propagate errors without wrapping in Failure:
The innermost Enclose has precedence:
Use a tag to pass an error to the outer Enclose:
Provide a constant function for f to return a fixed value in the event of any error:
Applications (3)
Text
Wolfram Research (2020), Enclose, Wolfram Language function, https://reference.wolfram.com/language/ref/Enclose.html.
CMS
Wolfram Language. 2020. "Enclose." Wolfram Language & System Documentation Center. Wolfram Research. https://reference.wolfram.com/language/ref/Enclose.html.
APA
Wolfram Language. (2020). Enclose. Wolfram Language & System Documentation Center. Retrieved from https://reference.wolfram.com/language/ref/Enclose.html