Differences between general exceptions and runtime exceptions in Java

Source: Internet
Author: User

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

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

The Java compiler forces us to catch these exceptions. Therefore, in the face of such exceptions

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

But there is another exception: runtime exception, also known as a runtime exception, which we can not handle

. When such an exception occurs, it is always taken over by the virtual machine. For example, we have never handled

Nullpointerexception is a running exception, which is the most common exception.

Common.

When an exception occurs during running, the system throws the exception to the upper layer and keeps processing the code. If

No processing block. To the top layer, thread. Run () throws multi-threading. If it is a single thread

Thrown by main. If the thread is thrown, the thread exits. If the main program throws

The program exits. An exception is a subclass of exception.

Can be processed by catch blocks. But we often don't handle it. That's it.

Yes. If you do not handle runtime exceptions, after a runtime exception occurs

Stop, or terminate the main program.

If you do not want to terminate, you must capture all running exceptions and never let the processing thread exit.

The exception data appears in the queue. The normal processing should be to discard the exception data and then record the log.

Normal data cannot be processed due to abnormal data. In this scenario, it may be

A good application does not mean that you should do this in all scenarios. In other scenarios,

When you encounter some errors, If you exit the program, you can ignore the running exception, or

The Controller exits by explicitly handling 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.