package jie.com;
import java.io.*;
public class ExceptionDemo {
/**
* @param args
*/
public static void main(String[] args) {
// TODO Auto-generated method stub
try
{
throw new ArithmeticException("异常测试");
}
catch(Exception e)
{
System.out.println(e.toString());
}
catch(ArithmeticException e)
{
System.out.println(e.toString());
}
}
}
//在声明异常捕捉时,要注意声明的次序,必须把异常的父类声明在子类的后面,不能像上面这样,否则会出现编译时错误;
//应该调换一下顺序:
/*package jie.com;
import java.io.*;
public class ExceptionDemo {
/**
* @param args
*/
/*public static void main(String[] args) {
// TODO Auto-generated method stub
try
{
throw new ArithmeticException("异常测试");
}
catch(ArithmeticException e)
{
System.out.println(e.toString());
}
catch(Exception e)
{
System.out.println(e.toString());
}
}
}*/