- 案例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