checked exception and unchecked exception
checked exception : 在编译时期,会被检测,代码会抛出的错误,你必须手动 try catch 或者向上层抛出;比如:FileNotFoundException;
unchecked exception:在编译时期不会被检测的异常;C++中所有的异常都是非检测异常;比如:ArithmeticException
Java exception中 Error 和 RunTimeException classes 是非受监测异常;其他的实现throwable 是检测异常;
+-----------+
| Throwable |
+-----------+
/ \
/ \
+-------+ +-----------+
| Error | | Exception |
+-------+ +-----------+
/ | \ / | \
\________/ \______/ \
+------------------+
unchecked checked | RuntimeException |
+------------------+
/ | | \
\_________________/
unchecked
标准:
If a client can reasonably be expected to recover from an exception, make it a checked exception. If a client cannot do anything to recover from the exception, make it an unchecked exception
https://www.geeksforgeeks.org/checked-vs-unchecked-exceptions-in-java/









网友评论