Throwable

来自jdk1.8

java.lang.Throwable

/**
 * The {@code Throwable} class is the superclass of all errors and
 * exceptions in the Java language. Only objects that are instances of this
 * class (or one of its subclasses) are thrown by the Java Virtual Machine or
 * can be thrown by the Java {@code throw} statement. Similarly, only
 * this class or one of its subclasses can be the argument type in a
 * {@code catch} clause.
{@code Throwable}类是所有错误和
Java语言中的异常的超类。只有这个类的实例或者
子类可由java虚拟机通过throw语句抛出。同样,只有这个类或其子类可做参数类型
在catch语句中捕获

* For the purposes of compile-time checking of exceptions, {@code
 * Throwable} and any subclass of {@code Throwable} that is not also a
 * subclass of either {@link RuntimeException} or {@link Error} are
 * regarded as checked exceptions.
为了在编译时检查异常,不是RuntimeException或Error的子类
被视为已检查的异常(checked exceptions)。

  * 

Instances of two subclasses, {@link java.lang.Error} and * {@link java.lang.Exception}, are conventionally used to indicate * that exceptional situations have occurred. Typically, these instances * are freshly created in the context of the exceptional situation so * as to include relevant information (such as stack trace data). java.lang.Error和java.lang.Exception表示异常情况发生。 Error和Exception的实例包括相关信息(如堆栈跟踪数据)

Throwable_第1张图片

Error(错误):是程序无法处理的错误,JVM中出现的错误。

Exception(异常):是程序本身可以处理的异常。

从另一个角度出发,java的Throwable分为已检查异常(checked exception)和未检查异常(unchecked exception)

已检查异常(checked exception):编译器要求必须处理的异常,代码中必须try-catch或throws,除去RuntimeException及其子类,其他的Exception类及其子类。

未检查异常(unchecked exception):编译器不要求必须处理的异常,运行时异常(RuntimeException与其子类)和错误(Error)

 

你可能感兴趣的:(JavaSE)