java中关于异常处理Java认证考试
文章作者 100test 发表时间 2010:01:01 15:51:31
来源 100Test.Com百考试题网
    
	
  //除零异常,不做处理
  class test{
  int devide(int x,int y)
  {return x/y.}
  }
  class TestException{
  public static void main(String arg[])
  {
  new test().devide(3,0).
  System.out.println("the end!!").
  }
  }
  //除零异常,进行捕获
  class test{
  int devide(int x,int y)
  {return x/y.}
  }
  class CatchException{
  public static void main(String arg[])
  {
  try{
  new test().devide(3,0).
  }
  catch(ArithmeticException l)//exception类 声名 对象l
  {//catch中可以执行其他语句输出
  // l.printStackTrace() .//printStackTrace
  // public void printStackTrace(PrintWriter s)
  // 将此 throwable 及其追踪输出到指定的 PrintWriter。