java异常

  • 分类:throwable的子类
    有 Error 和 Exception
  1. Error:一般是指与虚拟机相关的问题,如系统崩溃,虚拟机错误,内存空间不足,方法调用栈溢等。对于这类错 误的导致的应用程序中断,仅靠程序本身无法恢复和和预防,遇到这样的错误,建议让程序终止。
/**
 * An {@code Error} is a subclass of {@code Throwable}
 * that indicates serious problems that a reasonable application
 * should not try to catch. Most such errors are abnormal conditions.
 * The {@code ThreadDeath} error, though a "normal" condition,
 * is also a subclass of {@code Error} because most applications
 * should not try to catch it.
 * <p>
 * A method is not required to declare in its {@code throws}
 * clause any subclasses of {@code Error} that might be thrown
 * during the execution of the method but not caught, since these
 * errors are abnormal conditions that should never occur.
 *
 * That is, {@code Error} and its subclasses are regarded as unchecked
 * exceptions for the purposes of compile-time checking of exceptions.
  1. Exception:表示程序可以处理的异常,可以捕获且可能恢复。遇到这类异常,应该尽可能处理异常,使程序恢复运行,而不应该随意终止异常。
**
 * The class {@code Exception} and its subclasses are a form of
 * {@code Throwable} that indicates conditions that a reasonable
 * application might want to catch.
 *
 * <p>The class {@code Exception} and any subclasses that are not also
 * subclasses of {@link RuntimeException} are <em>checked
 * exceptions</em>.  Checked exceptions need to be declared in a
 * method or constructor's {@code throws} clause if they can be thrown
 * by the execution of the method or constructor and propagate outside
 * the method or constructor boundary.

  • 其中Exception可分为2种:
  1. RuntimeException:运行期异常,系统异常
    可以处理也可以不处理,编译器不强制用 try..catch 处理或用 throws 声明,所以系统异常也称为 unchecked 异常。
    eg:NullPointerException,IndexOutOfBoundsException,ClassCastException,ClassNotFoundException , IllegalArgumentException,UnsupportedOperationException。

  2. CheckedException: 也成编译器异常
    编译器强制普通异常必须 try..catch 处理或用 throws 声明继 续抛给上层调用方法处理
    eg:CloneNotSupportedException

最后编辑于
©著作权归作者所有,转载或内容合作请联系作者
平台声明:文章内容(如有图片或视频亦包括在内)由作者上传并发布,文章内容仅代表作者本人观点,简书系信息发布平台,仅提供信息存储服务。

推荐阅读更多精彩内容

  • 转载:http://www.cnblogs.com/lulipro/p/7504267.html 一、异常简介 程...
    SinX竟然被占用了阅读 995评论 2 2
  • 概念介绍 异常是发生在程序执行过程中阻碍程序正常执行的错误事件,当一个程序出现错误时,可能的情况有如下3种: 语法...
    niaoge2016阅读 5,248评论 2 20
  • 问:java 异常有哪几种,特点是什么? 答:异常是发生在程序执行过程中阻碍程序正常执行的错误操作,只要在 Jav...
    Little丶Jerry阅读 613评论 0 0
  • 本文部分来自于:代码钢琴家blog address:www.cnblogs.com/lulipro/p/75042...
    八目朱勇铭阅读 1,327评论 0 4
  • 也许这是大学里最后一次在这里和大家分享,因为感觉这样的机会太少,虽然我个人最开始觉得练讲有点麻烦。但当我在...
    小小以琳阅读 379评论 0 1