Why runtime exception is unchecked exception?

前端 未结 5 1213
庸人自扰
庸人自扰 2020-12-10 11:19

Generally if any class extends Exception , it becomes checked exception. Runtime exception also extends Exception. Then how is it unchecked e

5条回答
  •  被撕碎了的回忆
    2020-12-10 11:33

    Yes. Any Throwable is a checked exception, except for Error, RuntimeException, and (direct or indirect) subclasses thereof.

    However, these are checked by the compiler, not by the JVM; checked exceptions are a compile-time feature, not a run-time feature. (Update: And I now see that you've edited your question to specify "compiler" rather than "JVM". ☺)


    To elaborate a bit further . . . it's not as though there were any sort of "checked-exception" interface. The logic is simply hard-coded: "any exception class is a checked exception unless it's a subtype of RuntimeException or Error".

提交回复
热议问题