error与exception

来源:互联网 发布:漫画描线软件 编辑:程序博客网 时间:2024/06/05 14:08

1)error继承于父类java.lang.Error;exception继承于父类java.lang.exception。

2)error是一种严重错误,根本不应该发生的,所以不应该去try/catch;exception是一种运行的条件应该用try/catch。  

3)error和runtimeException及其子类都是unchecked exceptions,其余exception为checked exceptions。

说明:

checked exceptions是一种可以恢复的程序中抛出来的异常,建议使用try/catch比如FileNotFoundException, ParseException;

unchecked exceptions是一种在正常情况下不应该发生的。不建议try/catch,属于bug,建议修复,否则出现应该让其运行停止查明原因,例如ArrayIndexOutOfBoundException, ClassCastException

0 0
原创粉丝点击