Catch
Usage
• Catch[expr] 返回在计算expr时产生的第一个Throw的参数。
• Catch[expr, form]返回从form匹配tag的第一个 Throw[value, tag]值。
• Catch[expr, form, f] 返回f[value, tag].
Notes
如果在计算时不产生Throw,则 Catch[expr, ... ]总是返回expr的值。 • form 可以是任何表达式,经常是一个模式。 • Throw[value, tag]中的tag和form相比较时每次重新计算。
• 参见 Mathematica 全书: 节 2.5.9.
Further Examples
This function throws overflow if its argument is greater than 10.
In[1]:=
|
g[20] throws overflow, which is returned as the value of the enclosing Catch.
In[2]:=
|
Out[2]=
|
In this case, overflow is not generated, and the Catch has no effect.
In[3]:=
|
Out[3]=
|
|