Java exceptions-differences between general and run-time exceptions

Source: Internet
Author: User

Java provides two main types of exceptions: Runtime exception and checked exception. Checked

Exceptions are the IO exceptions that we often encounter, and SQL exceptions are exceptions. For this exception,

The Java compiler enforces the need for us to catch these exceptions that occur. So, in the face of this anomaly

Whether we like it or not, we can only write a lot of catch blocks on our own to handle possible exceptions.

  In a word, runtime exception can not be captured, automatically thrown out by the program, checked exception must be captured (Try/catch), must be processed now;

But another exception: Runtime exception, also known as runtime exception, we can not handle

。 When such an exception occurs, it is always taken over by the virtual machine. Like: We've never been dealt with.

NullPointerException exception, which is a run-time exception, and this exception is the most common

Often one.

When a run-time exception occurs, the system throws the exception all the way to the top and continues to experience processing code. If

There is no processing block, to the topmost, if it is multithreaded by Thread.run () thrown, if it is a single thread on

Thrown by main (). Once thrown, the thread exits if it is a thread. If the main program is thrown

out of the exception, then this entire program also exits . The run-time exception is a subclass of exception, and there is also a

The exception is that it can be handled by a catch block. It's just that we're not dealing with him. So

That is, if you do not handle a run-time exception, then a run-time exception occurs, either a thread

Abort, or the main program terminates.

If you do not want to terminate, you must catch all run-time exceptions and never let the processing thread exit.

Abnormal data in the queue, the normal processing should be to discard the abnormal data, and then log.

The handling of normal data should not be affected by abnormal data. In this scenario this treatment may be

A good app, but it doesn't mean you should do it in all scenarios. If in other scenarios,

Encountered some errors, if you exit the program is better, then you can ignore the run-time exception, or

The program exits by explicit control of the exception's handling.

Java exceptions-differences between general and run-time 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.