我正在查看 RuntTimeException
类,但它未在编译时检查。为什么一个类在编译时不被检查
而在运行时不被检查
?
https://docs.oracle.com/javase/7/docs/api/java/lang/RuntimeException.html
| Throwable |
+-----------+
/ \
/ \
+-------+ +-----------+
| Error | | Exception |
+-------+ +-----------+
/ | \ / | \
\________/ \______/ \
unchecked checked
+------------------+
| RuntimeException |
+------------------+
/ | | \
\_________________/
unchecked
RuntimeException
类扩展了Exception
类但仍未检查?如何?。- 编译器如何决定是否应在
运行时
或编译
时检查此类?
最佳答案
RuntimeException class extends Exception class and still is unchecked? How?.
这是一种设计选择。 Java 语言的设计者决定 RuntimeException 和 Error,以及扩展它们的类根据定义是未经检查的异常。所以这只是语言的规则。
How does the compiler decides whether this class should be checked in runtime or compile time?.
编译器检查抛出的异常类型。如果它是 RuntimeException 或 Error,则异常未检查。
关于java - 如何确定异常是编译时检查还是运行时检查?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/27424855/