为什么 ThreadDeath class 不叫 ThreadDeathError 呢?

Why is the ThreadDeath class not called ThreadDeathError instead?

Java 中的几乎所有 Error 子类的名称中都包含“-Error”后缀,但 ThreadDeath 除外。为什么是这样?这让人很难记住它是 Error 还是 Exception 的子类。

ThreadDeath 的 javadoc 是这样说的:

An application should catch instances of this class only if it must clean up after being terminated asynchronously. If ThreadDeath is caught by a method, it is important that it be rethrown so that the thread actually dies.

The class ThreadDeath is specifically a subclass of Error rather than Exception, even though it is a "normal occurrence", because many applications catch all occurrences of Exception and then discard the exception.

它的意思是,应用程序应该将 ThreadDeathboth Exception and 区别对待(其他) Error classes.

由于应该区别对待异常,因此使用不符合正常模式的 class 名称是有意义的。


但是,无论如何,这应该具有历史意义。 Thread.stop() 抛出这个的方法在 20 多年前就被弃用了。你的代码不应该使用 stop(),因此不需要关心这个异常。你也不应该。