DOCUMENTATION CENTER SEARCH
Mathematica
>
Flow Control
>
Built-in
Mathematica
Symbol
Loops and Control Structures
Tutorials »
|
Throw
Check
CheckAbort
Reap
See Also »
|
Flow Control
Looping Constructs
Procedural Programming
Scoping Constructs
More About »
Catch
Catch
[
expr
]
returns the argument of the first
Throw
generated in the evaluation of
expr
.
Catch
[
expr
,
form
]
returns
value
from the first
Throw
[
value
,
tag
]
for which
form
matches
tag
.
Catch
[
expr
,
form
,
f
]
returns
f
[
value
,
tag
]
.
MORE INFORMATION
Catch
[
expr
,
...
]
always returns the value of
expr
if no
Throw
was generated during the evaluation.
form
can be any expression, and is often a pattern.
tag
in
Throw
[
value
,
tag
]
is re-evaluated every time it is compared to
form
.
EXAMPLES
CLOSE ALL
Basic Examples
(3)
Exit to the enclosing
Catch
as soon as the
Throw
is evaluated:
In[1]:=
Out[1]=
Define a function that can "throw an exception":
In[1]:=
The result of the
Catch
is just what is thrown by
Throw
:
In[2]:=
Out[2]=
In[3]:=
Out[3]=
Use
Throw
to exit a loop when a criterion is satisfied:
In[1]:=
Out[1]=
Scope
(5)
Generalizations & Extensions
(3)
Applications
(3)
Properties & Relations
(1)
SEE ALSO
Throw
Check
CheckAbort
Reap
TUTORIALS
Loops and Control Structures
MORE ABOUT
Flow Control
Looping Constructs
Procedural Programming
Scoping Constructs
RELATED LINKS
NKS|Online
(
A New Kind of Science
)
New in 1 | Last modified in 3
© 2008 Wolfram Research, Inc.