public class ExcepTest {
/**
* @param args
*/
public static void main(String[] args) {
System.err.println("111111111111");
// say(); //抛出异常,但是代码不显示的try..catch..
// calc(); //抛出异常,但是代码不显示的try..catch..
// try {
// show();
// } catch (Exception e) {
// e.printStackTrace();
// System.err.println("异常成功捕获。。");
// }
// try {
// view();
// } catch (Exception e) {
// e.printStackTrace();
// System.err.println("异常成功捕获。。");
// }
calc22();
System.err.println("222222222222");
}
public static void say(){ //new NullPointerException
System.err.println("say>>>>");
throw new NullPointerException();
}
public static void calc() { //throws ArithmeticException ,这个异常不提示。
System.err.println("calc>>>>");
int i = 0, j = 0;
System.err.println( i/j );
}
public static void show() throws Exception{ //这个异常提示。
System.err.println("show>>>>");
int i = 0, j = 0;
System.err.println( i/j );
}
public static void view() throws Exception{
System.err.println("view>>>>");
throw new Exception();
}
public static void calc22(){
System.err.println("calc22>>>>");
try {
int i = 0, j = 0;
int k = i/j ;
} catch (Exception e) {
System.err.println("异常处理完毕。。。。");
// throw e; //异常再度抛出。
// throw new ArithmeticException(); //继承自exception的则是检查型异常(当然,runtimeexception本身也是exception的子类
// throw new RuntimeException(); //(当然,runtimeexception本身也是exception的子类
//继承自runtimeexception或error的是非检查型异常
//ArithmeticException继承RuntimeException
}
System.err.println("calc22>>>>calc22");
}
}