Catch
范例
打开所有单元 关闭所有单元基本范例 (3)
Catch[a;b;Throw[c];d;e]f[x_] := If[x > 10, Throw[overflow], x!]Catch[f[2] + f[11]]Catch[f[2] + f[3]]当判别式被满足时,利用 Throw 退出循环:
Catch[Do[If[i! > 10 ^ 10, Throw[i]], {i, 100}]]范围 (5)
Catch[If[# < 0, Throw[#]]& /@ {1, 2, 0, -1, 5, 6}]Catch[{a, Throw[b], c}]Catch[a ^ 2 + b ^ 2 + c ^ 2 /. b :> Throw[bbb]]Catch[{Catch[{a, Throw[b], c}], d, e}]Catch[{Throw[a], Throw[b], Throw[c]}]Catch[Throw /@ {a, b, c}]f[x_] := (If[x < 0, Throw["negative"]];Sqrt[x])Catch[Sum[f[i], {i, 5, -5, -1}]]f[x_] := Which[
x < 0, Throw[x, error[negative]],
x == 0, Throw[x, error[zero]],
True, 1 / Sqrt[x]]ff[x_] :=
Catch[f[x], error[_], Function[{value, tag}, tag /. {error[negative] :> Indeterminate, error[zero] :> Infinity, _ :> Throw[value, tag]}]]ff /@ {-1, 0, 1}推广和延伸 (3)
应用 (3)
Catch[Do[If[PrimeQ[i], Throw[i]], {i, 10 ^ 10, 10 ^ 10 + 1000}]]Catch[Do[If[Mod[17 ^ i, 19] == 1, Throw[i]], {i, 19}]]NestList[# ^ 2 + 1&, 2, 6]Catch[NestList[If[# > 1000, Throw[#], # ^ 2 + 1]&, 2, 6]]属性和关系 (1)
如果产生信息,利用 Check 抛出一个异常:
Catch[2 + Check[1 / (1 + 1 / 0), Throw[error]]]Catch[2 + Check[1 / (1 + 1 / 2), Throw[error]]]技术笔记
-
▪
- 循环控制结构
历史
1988年引入 (1.0) | 在以下年份被更新:1996 (3.0)
文本
Wolfram Research (1988),Catch,Wolfram 语言函数,https://reference.wolfram.com/language/ref/Catch.html (更新于 1996 年).
CMS
Wolfram 语言. 1988. "Catch." Wolfram 语言与系统参考资料中心. Wolfram Research. 最新版本 1996. https://reference.wolfram.com/language/ref/Catch.html.
APA
Wolfram 语言. (1988). Catch. Wolfram 语言与系统参考资料中心. 追溯自 https://reference.wolfram.com/language/ref/Catch.html 年
BibTeX
@misc{reference.wolfram_2026_catch, author="Wolfram Research", title="{Catch}", year="1996", howpublished="\url{https://reference.wolfram.com/language/ref/Catch.html}", note=[Accessed: 19-August-2026]}
BibLaTeX
@online{reference.wolfram_2026_catch, organization={Wolfram Research}, title={Catch}, year={1996}, url={https://reference.wolfram.com/language/ref/Catch.html}, note=[Accessed: 19-August-2026]}