您的位置:首页 > 编程语言 > Java开发

JAVA异常学习笔记

2007-09-03 02:37 465 查看
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());
}

}

}*/
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: