当前位置:网站首页>Difference and understanding between detected and non detected anomalies

Difference and understanding between detected and non detected anomalies

2022-07-06 13:39:00 Wake up duck, did you program today?

1、 B. abnormal

The so-called checked exception actually indicates that it is at the time of compilation , Exceptions to force check , This exception needs to be displayed through try/catch To capture or through throws Throw it out, otherwise the program cannot be compiled .

2、 Undetected abnormal

The so-called unchecked exception means that the compiler does not need to force to check the exception , This exception does not need to be displayed to catch or throw .

stay java All exceptions inside need to be inherited java.lang.Throwable This class is shown below :

Throwable There are two direct subclasses :

  1. Error: It refers to errors at the bottom of the program or at the hardware level , Like the usual OOM abnormal ( Memory overflow exception ) So this exception has nothing to do with the program itself, so it doesn't need to check whether it belongs to Undetected abnormal .
  2. Exception: It indicates some exceptions in the program , It may be caused by lax procedures, such as NullPointerException( Null pointer exception ) etc. ,Exception Two exception types are derived
    1. RuntimeException: The runtime exception belongs to the non inspected exception
    2. other Exception

Summary :

So in addition to Error and RuntimeException as well as RuntimeException Outside the derived class of , Other exceptions belong to the detected exceptions, such as :IOException and SQLException, In fact, the reason is Java I think the main reason for designing some exceptions for mandatory inspection is :

Consider the correctness of the program 、 stability 、 reliability , As mentioned above, database exceptions are unexpected exceptions of the program, but once there is a problem, it will cause an occupation of resources and cause some problems in the program , So we need to catch these problems. Once there is a problem, we can deal with it in time , If we operate the database try/catch And then finally close xxx.close Close the connection , So generally speaking, the detected exception is an exception that cannot be judged in the program. Let's use try/catch Capture .

原网站

版权声明
本文为[Wake up duck, did you program today?]所创,转载请带上原文链接,感谢
https://yzsam.com/2022/187/202207060916452110.html