Catch
✖
Catch
Examples
open allclose allBasic Examples (3)Summary of the most common use cases
Exit to the enclosing Catch as soon as the Throw is evaluated:

https://wolfram.com/xid/0y76co-kp4

Define a function that can "throw an exception":

https://wolfram.com/xid/0y76co-gq0
The result of the Catch is just what is thrown by Throw:

https://wolfram.com/xid/0y76co-f8o


https://wolfram.com/xid/0y76co-rfa

Use Throw to exit a loop when a criterion is satisfied:

https://wolfram.com/xid/0y76co-c34

Scope (5)Survey of the scope of standard use cases
Catch can catch a Throw from inside essentially any function:

https://wolfram.com/xid/0y76co-yal


https://wolfram.com/xid/0y76co-yfa


https://wolfram.com/xid/0y76co-f8w

The nearest enclosing Catch catches the Throw:

https://wolfram.com/xid/0y76co-y40

Catch picks up the first Throw that is evaluated:

https://wolfram.com/xid/0y76co-u


https://wolfram.com/xid/0y76co-x87

Throw need not occur lexically inside Catch:

https://wolfram.com/xid/0y76co-bdikhw

https://wolfram.com/xid/0y76co-npb522

A function that can throw a number of different exceptions:

https://wolfram.com/xid/0y76co-fmolww
A handler for the possible exceptions:

https://wolfram.com/xid/0y76co-laohle

https://wolfram.com/xid/0y76co-32ihy

Generalizations & Extensions (3)Generalized and extended use cases
Catch the Throw with tag u:

https://wolfram.com/xid/0y76co-tax

The inner Catch catches the Throw:

https://wolfram.com/xid/0y76co-wu9

The outer Catch catches the Throw:

https://wolfram.com/xid/0y76co-iog


https://wolfram.com/xid/0y76co-uxg

Applications (3)Sample problems that can be solved with this function
Find the next prime after 1010:

https://wolfram.com/xid/0y76co-vr3

Find the first power of 17 equal to 1 mod 19:

https://wolfram.com/xid/0y76co-bcn

Stop if an iteration gets too large:

https://wolfram.com/xid/0y76co-vx3


https://wolfram.com/xid/0y76co-is4

Properties & Relations (1)Properties of the function, and connections to other functions
Use Check to throw an exception if a message is generated:

https://wolfram.com/xid/0y76co-frl



https://wolfram.com/xid/0y76co-j0n

Wolfram Research (1988), Catch, Wolfram Language function, https://reference.wolfram.com/language/ref/Catch.html (updated 1996).
Text
Wolfram Research (1988), Catch, Wolfram Language function, https://reference.wolfram.com/language/ref/Catch.html (updated 1996).
Wolfram Research (1988), Catch, Wolfram Language function, https://reference.wolfram.com/language/ref/Catch.html (updated 1996).
CMS
Wolfram Language. 1988. "Catch." Wolfram Language & System Documentation Center. Wolfram Research. Last Modified 1996. https://reference.wolfram.com/language/ref/Catch.html.
Wolfram Language. 1988. "Catch." Wolfram Language & System Documentation Center. Wolfram Research. Last Modified 1996. https://reference.wolfram.com/language/ref/Catch.html.
APA
Wolfram Language. (1988). Catch. Wolfram Language & System Documentation Center. Retrieved from https://reference.wolfram.com/language/ref/Catch.html
Wolfram Language. (1988). Catch. Wolfram Language & System Documentation Center. Retrieved from https://reference.wolfram.com/language/ref/Catch.html
BibTeX
@misc{reference.wolfram_2025_catch, author="Wolfram Research", title="{Catch}", year="1996", howpublished="\url{https://reference.wolfram.com/language/ref/Catch.html}", note=[Accessed: 16-April-2025
]}
BibLaTeX
@online{reference.wolfram_2025_catch, organization={Wolfram Research}, title={Catch}, year={1996}, url={https://reference.wolfram.com/language/ref/Catch.html}, note=[Accessed: 16-April-2025
]}