Failsafe

Failsafe[f][x1,x2,]

returns f[x1,x2,] if none of the xi is considered a failure, and the first failing xi otherwise.

Failsafe[f,test][x1,x2,]

returns f[x1,x2,] if test[x1,x2,] gives True, and Failure[] otherwise.

Failsafe[f,test,failf][x1,x2,]

returns failf[x1,x2,] if test[x1,x2,] does not give True.

Details

Examples

open allclose all

Basic Examples  (2)

Apply a failsafe version of a function:

The failsafe version returns the argument unchanged when it is a failure:

Make a failsafe version of Sqrt that only applies to positive numbers:

Scope  (2)

Map a failsafe function over a list, leaving existing failures unchanged:

Failsafe functions can be applied to multiple arguments:

By default, it fails if any arguments are considered a failure:

test and failf are applied to all arguments at once:

Applications  (1)

Make a version of Divide that returns Missing[] when its second argument is 0:

Properties & Relations  (4)

Failsafe[f][x1,x2,] returns the first xi that fails:

Failsafe[f,test][x1,x2,] applies test to all the xi simultaneously:

x=!=y=!=z
True

Failsafe[f,test,failf][x1,x2,] applies failf to all the xi simultaneously:

Failsafe can often be approximated with Confirm and Enclose:

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

Text

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

CMS

Wolfram Language. 2025. "Failsafe." Wolfram Language & System Documentation Center. Wolfram Research. https://reference.wolfram.com/language/ref/Failsafe.html.

APA

Wolfram Language. (2025). Failsafe. Wolfram Language & System Documentation Center. Retrieved from https://reference.wolfram.com/language/ref/Failsafe.html

BibTeX

@misc{reference.wolfram_2024_failsafe, author="Wolfram Research", title="{Failsafe}", year="2025", howpublished="\url{https://reference.wolfram.com/language/ref/Failsafe.html}", note=[Accessed: 15-January-2025 ]}

BibLaTeX

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