Sjo*_*erd 7 oop exception-handling exception try-catch
我应该在try中放入多个语句然后捕获所有可能的异常,还是应该只在try语句中放入一个语句?
例:
try {
MaybeThrowIOException();
MaybeThrowFooBarException();
return true;
} catch (IOException e) {
// ...
} catch (FooBarException e) {
// ...
}
Run Code Online (Sandbox Code Playgroud)
要么
try {
MaybeThrowIOException();
} catch (IOException e) {
// ...
}
try {
MaybeThrowFooBarException();
} catch (FooBarException e) {
// ...
}
return true;
Run Code Online (Sandbox Code Playgroud)
归档时间: |
|
查看次数: |
3388 次 |
最近记录: |