gpt4 book ai didi

exception - try/catch 语句中有多少条语句?

转载 作者:行者123 更新时间:2023-12-04 10:06:03 26 4
gpt4 key购买 nike

我应该在 try 中放入多个语句然后捕获所有可能的异常,还是应该在 try 语句中只放入一个语句?

例子:

try {
MaybeThrowIOException();
MaybeThrowFooBarException();
return true;
} catch (IOException e) {
// ...
} catch (FooBarException e) {
// ...
}

或者

try {
MaybeThrowIOException();
} catch (IOException e) {
// ...
}

try {
MaybeThrowFooBarException();
} catch (FooBarException e) {
// ...
}

return true;

最佳答案

包装您的关键部分,以保持您的信息清晰和切题。

关于exception - try/catch 语句中有多少条语句?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/2086769/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com