Checked exception and runtime exception

Source: Internet
Author: User

Java has three throwable structures: checked exception, runtime exception, and error ). The usage principle is:

1. If the caller is expectedRecoverable. If an exception is thrown, the caller can force the caller to handle the exception in a catch clause, or continue propagation.

2. runtime exceptions referHard to recover or unrecoverableProgram error. Most runtime exceptions indicate a prerequisite violation (precondition violation indicates that the API caller does not follow the call conventions ).

3. ErrorJVM reservation indicates insufficient resources, constraints failed, or other programs cannot be executed.. It is best not to implement a new error subclass. All unchecked exceptions thrown should be child classes of runtimeexception.

Runtime exceptionIt can be avoided by the standardization of programmer programming.

Application scenarios: If you want to terminate the program, a running exception is thrown. If you want to handle the exception, a check exception is thrown.

 

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.