JDK1.8源码解读之Exception

934 阅读1分钟

概述

Exception 类及其子类是 Throwable 的一种形式,它表示合理的应用程序可能希望捕获的条件。

Exception分类
  • RuntimeException 是指运行时的一些异常
  • CheckedException 是编译阶段的一些异常

继承关系

public class Exception extends Throwable

继承自 Throwable

构造器

protected 构造器 message 记录了 Exception 的信息, cause 记录了 Exception 的一些原因 enableSuppression 是否允许抑制 writableStackTrace 表示是否记录堆栈轨迹

protected Exception(String message, Throwable cause,
                    boolean enableSuppression,
                    boolean writableStackTrace) {
    super(message, cause, enableSuppression, writableStackTrace);
}

此外还有3个重载方法:参数稍有不一致。

public Exception() {
    super();
}
public Exception(String message) {
    super(message);
}
public Exception(String message, Throwable cause) {
    super(message, cause);
}
public Exception(Throwable cause) {
    super(cause);
}

结语

源码非常简短,就只有几个构造函数,没有成员变量和方法。

希望和大家多多交流


我16年毕业以后,做的是前端,目前打算深入学习java开发。内容有任何问题,欢迎各位小伙伴们指正,也希望小伙伴们给我点赞和关注,给我留言,一起交流讨论,共同进步。