“try-catch”是编程中的异常处理结构:把可能出错的代码放在 try 里运行;如果发生异常(错误情况),就由 catch 捕获并处理,从而避免程序直接崩溃。(不同语言还可能有 finally、多重 catch 等扩展用法。)
/ˈtraɪ kæʧ/
I used a try-catch to handle the error.
我用 try-catch 来处理这个错误。
If the file can’t be opened, the try-catch block logs the exception and continues running instead of crashing.
如果文件打不开,try-catch 代码块会记录异常并继续运行,而不是直接崩溃。
来自英语动词 try(“尝试”)与动词 catch(“抓住、捕获”)的组合,在编程语境中分别引申为“尝试执行(可能失败的代码)”与“捕获(异常)”。该结构随现代编程语言的异常机制普及而广泛使用,尤其常见于 Java、C#、JavaScript、Python(对应 try/except)等语言的错误处理模式中。
try...catch。