Java check exceptions and Non-check exceptions

Source: Internet
Author: User

Personal opinion, If there is a problem, but also hope that the great God to correct

1. Non-check exception is called Run-time exception, all inherited from RuntimeException exception is Non-check exception, if you do not handle will have virtual machine Main method handle

2. Exceptions that do not inherit from RuntimeException are check exceptions (such as IO Exceptions)

3. The upper caller must handle the check Exception: Try_catch or continue throws to the upper layer

4. Why check exceptions: typically, checking for exceptions is not a problem with your program writing, which is an exception that was previously caused by external factors: such as disk full, no write Permission. Obviously these are not the reasons for your Program.

But you can not avoid these situations, in the event of these situations, you do not handle, continue to execute your program, may be wrong. All for better coding or to try to avoid errors, Java provides check exceptions,

This means that the program forces you to handle these possible situations to avoid the next program error ...

So I personally understand that checking for exceptions is more like checking than exceptions. Just as

If (does not meet the criteria 1)

Return 0;

else if (not eligible 2)

Return 1;

Else check through, continue execution

But returning 0, 1 is clearly not an intuitive representation of the Problem. And There's no way to force you to deal with this Situation. All occurrences of a check exception, by throws an exception, which upper layer must be processed, either processed, or continued to the higher layer. anyway, someone has to deal with it.

Java check exceptions and Non-check exceptions

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.