"Java" check-type and non-checked exceptions

Source: Internet
Author: User

Check type exception (checkedexception)
all exception that are not runtimeexception derived in Java are check-type exceptions. The function declaration of a function must contain a throws statement when there is an operation that throws a check-type exception. A function that invokes a function must also handle the exception , and if it is not processed, it must declare the throws statement on the calling function.

The check-type exception is the first in Java, and it is mandatory to handle the exception at compile time. A large number of exceptions in JDK code are check-type exceptions, including Ioexception,sqlexception, and so on.

Non-checked exception (uncheckedexception)
all runtimeexception derived classes in Java are non-check exceptions, compared to check exceptions, non-check exceptions can not add throws statements in the function declaration , and there is no need to force processing on the calling function.
Common nullpointexception,classcastexception are common non-checked exceptions. Non-checked exceptions can be handled without Try...catch , but if an exception is generated, the exception is handled by the JVM . for RuntimeException subclasses it is best to also use exception handling mechanisms. Although runtimeexception exceptions can be handled without the use of Try...catch, if an exception occurs, it is sure to cause the program to break execution, so in order to ensure that the program can still execute after the error, it is best to use try when developing the code ... The exception handling mechanism for catch is processed.

"Java" check-type and non-checked exceptions

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.