public class ExceptionTest01 {
public static void main(String[] args) {
try {
Test tt = new Test();
tt.t();
} catch (NumberFormatException e) {
e.printStackTrace();
} catch (NullPointerException e) {
e.printStackTrace();
} catch (Exception e) {
e.printStackTrace();
}
}
}class Test {
protected void t() throws NullPointerException, NumberFormatException {
throw new NullPointerException("空指向异常");
System.out.println("hello world");
throw new NumberFormatException("数据格式异常");
}
}问题:为什么不能同时抛出两个异常类的对象俺是菜鸟,需要请教gf
public static void main(String[] args) {
try {
Test tt = new Test();
tt.t();
} catch (NumberFormatException e) {
e.printStackTrace();
} catch (NullPointerException e) {
e.printStackTrace();
} catch (Exception e) {
e.printStackTrace();
}
}
}class Test {
protected void t() throws NullPointerException, NumberFormatException {
throw new NullPointerException("空指向异常");
System.out.println("hello world");
throw new NumberFormatException("数据格式异常");
}
}问题:为什么不能同时抛出两个异常类的对象俺是菜鸟,需要请教gf
catch (NullPointerException e) {
e.printStackTrace();
}
完后程序就结束了
* @param args
*/
public static void main(String[] args) {
// TODO Auto-generated method stub
try {
throw new NullPointerException("空指针异常");
} catch (NullPointerException e) {
e.printStackTrace();
} finally {
throw new NumberFormatException("数字转换异常");
}
}
}