Throw
Usage
• Throw[value]停止计算并返回value作为最接近包含Catch的值。
• Throw[value, tag]仅由 Catch[expr, form]返回,其中form是匹配tag的模式。
Notes
• 可以使用Throw和Catch退出诸如 Nest, Fold, FixedPoint和Scan的函数。 • tag 可以是任何表达式。 • Throw[value, tag]中的tag在每次与Catch[expr, form]中的form比较时被重新计算。 • 如果没有适当关闭捕获Throw的Catch时,将产生一个错误,返回一个未计算的Throw。 • 参见 Mathematica 全书 : 节 2.5.9.
Further Examples
This definition makes g throw overflow if its argument is greater than 10.
In[1]:=
|
In[2]:=
|
Out[2]=
|
In[3]:=
|
|