從不顯示異常。 擴展Exception
類並重寫方法toString
。然後調用它。根據條件它應該顯示哈哈,但它不顯示任何內容..也沒有錯誤。自定義清除不投擲
class Excp extends Exception {
public String toString() {
return "hahah";
}
}
public class exc {
boolean a = false;
void hey() throws Excp {
if (a)
throw new Excp();
}
public static void main(String... s) {
try {
new exc().hey();
} catch (Excp e) {
System.out.println(e);
}
}
}
+1只是幾秒鐘的差異 –
@JunedAhsan你打敗了我很多次我的朋友:) –
,我覺得非常愚蠢的現在:(。什麼是一個糟糕的錯誤 – user2837260