Eclipse沒有顯示錯誤,卻運行不了
(class 1:)
package com.imooc.test;
public class DrunkException extends Exception {
public DrunkException(){
}
public DrunkException(String message){
super(message);
}
}
(Class 2:)
package com.imooc.test;
public class ChainTest {
/**
* test1():拋出“喝大了”異常
* test2():嘗試捕獲“喝大了”異常,并且包裝成運行時異常,繼續(xù)拋出
* main方法中,調(diào)用test2(),嘗試捕獲test2()方法拋出的異常
* @param args
*/
public static void main(String[] args) {
// TODO Auto-generated method stub
ChainTest ab=new ChainTest();
//use the try-catch to surround the test2()
try {
ab.test2();
}catch(Exception e){
e.printStackTrace();
}
}
?
public void test1() throws DrunkException{
throw new DrunkException("開車別喝酒");
}
?
public void test2() {
try {
test1();
} catch (DrunkException e) {
//新建一個RuntimeException的方法,并將捕獲的異常傳遞給它
RuntimeException newExc=?
new RuntimeException("司機一滴酒,親人兩行淚");
//newExc.initCause(e);
throw newExc;
}
}
}
運行結(jié)果:
請問這是什么問題呢???
2018-05-19
The public type DrunkException must be defined in its own file.是必須在自己的文件中定義公共類型DunkExcExchange。
The serializable class DrunkException does not declare a static final serialVersionUID field of type long是可序列化類DunkExct不聲明靜態(tài)最終序列。
我百度的,這時候重啟一下應(yīng)該是最好的吧
2018-03-23
Erroe錯誤是你系統(tǒng)崩潰了
2018-03-18
控制臺里面的紅色是報錯了了吧
2018-03-15
不知道哎