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

解决方案 »

  1.   

    抛出NullPointerException后程序就进入
    catch (NullPointerException e) {
    e.printStackTrace();

    完后程序就结束了
      

  2.   

    流程控制问题public class Test6 { /**
     * @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("数字转换异常");
    }
    }
    }