- 案例1和2的效果相同,为什么需要在方法签名中添加异常声明?在方法签名中解释“抛出异常”的效果是什么
//情况1
public void doSomething() throws Exception {
//do Something
}
public void Caller() {
try {
doSomething();
} catch (Exception e) {
//handle the exception
}
}
//情况下2
public void doSomething() {
//do Something
}
public void Caller() {
try {
doSomething();
} catch (Exception e) {
//handle the exception
}
}
参考: what is the use of throws Exception
你的答案是明确的,还提供有用的信息和建议,而不是我的问题,非常感谢! – kevin 2014-11-22 17:40:31