Exception

作者: 93张先生 | 来源:发表于2019-11-21 22:00 被阅读0次

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/

相关文章

网友评论

      本文标题:Exception

      本文链接:https://www.haomeiwen.com/subject/txyxwctx.html