Understanding of checked and non-checked exceptions

Source: Internet
Author: User

Understanding of checked and non-checked exceptions
From the beginning, I learned how to handle exceptions. I know that exceptions are classified into checking exceptions and non-checking exceptions. RuntimeException is a non-checking exception and knows the types of exceptions. However, there were not many practical applications before work, and the definitions on the courseware in the books were not very clear about the two exceptions. After work, I gradually learned the basics in the actual code. Here I will record it and I will not talk about it. The courseware on the book is rich in online materials, here we only summarize the understanding of the two exceptions. 1. Check exception: the JAVA compiler forces the use of try {} catch () {} block for processing, if the program is not compiled, an exception must be thrown on the throws display in the method that contains code that may cause an exception. The catch method that calls the method will catch the exception. Otherwise, the program compilation will not pass, there will be a Red Cross prompt. For example:

 

Here, try catch block must be used to enclose the code or throws explicitly throw an exception, otherwise the compilation will not pass. 2. Non-checkable exceptions: exceptions that can be passed by the JAVA compiler can be handled using try {} catch () {}. After processing, the program can continue to execute downward or not, it is processed by the method called. Of course, it can also be left blank. At the top layer, the thread will be terminated if multiple threads are used, and the main program will be terminated if a single thread is used. That is to say, if a running exception is not processed, it will stop the program. For example:

 

Although an exception is thrown here, it only prevents the program from continuing to run and does not cause compilation errors. You do not need to explicitly throw an exception using the throws statement in the method.

Related Article

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.