一个try / catch语句中有多少个语句? [英] How many statements in a try/catch statement?
本文介绍了一个try / catch语句中有多少个语句?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
示例:
try {
MaybeThrowIOException();
MaybeThrowFooBarException();
返回true;
} catch(IOException e){
// ...
} catch(FooBarException e){
// ...
}
或
try {
MaybeThrowIOException();
} catch(IOException e){
// ...
}
try {
MaybeThrowFooBarException();
} catch(FooBarException e){
// ...
}
return true;
解决方案
包装关键部分保持你的消息清楚,并指出。
Should I put multiple statements in a try and then catch all possible exceptions, or should I put only one statement in the try statement?
Example:
try {
MaybeThrowIOException();
MaybeThrowFooBarException();
return true;
} catch (IOException e) {
// ...
} catch (FooBarException e) {
// ...
}
Or
try {
MaybeThrowIOException();
} catch (IOException e) {
// ...
}
try {
MaybeThrowFooBarException();
} catch (FooBarException e) {
// ...
}
return true;
解决方案
Wrap your critical parts to keep your message clear and to the point.
这篇关于一个try / catch语句中有多少个语句?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文