Run-time exception and non-run are exceptions

Source: Internet
Author: User

Throwable is the parent class for error handling in all Java programs, and there are two types of assets:ErrorAndException

Error:Represents an unexpected error detected by the JVM, because it is a critical error at the JVM level that prevents the JVM from continuing, so this is not a snap and cannot take any recovery actions, at most, only error messages.

Exception:Represents a recoverable exception, which can be captured.

Java provides two main types of exceptions:Runtime ExceptionAndChecked Exception。 The checked exception is the IO exception that we often encounter, and the SQL exception is the exception. For this exception, the Java compiler enforces that we must catch the exceptions that occur. So, in the face of such anomalies whether we like it or not, we can only write a lot of catch blocks to deal with possible exceptions.

But another exception:Runtime Exception, also called run-time exceptions, 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.NullPointerExceptionException, which is a run-time exception, and is one of the most common exceptions.

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 level, if it is multithreading is thrown by Thread.run (), if it is a single thread is thrown by main (). Once thrown, the thread exits if it is a thread. If the exception is thrown by the main program, then the entire program exits. Runtime exceptions are subclasses of the exception, and there are general exceptions that can be handled by catch blocks. It's just that we're not dealing with him. That is, if you do not handle a run-time exception, then a run-time exception occurs, either the thread aborts 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. This can be a good application in this scenario, but it does not mean that you should do so in all scenarios. If, in other scenarios, you encounter some errors, if you exit the program better, then you can ignore the runtime exception, or by the exception of the handling of explicit control program exit.

One of the goals of exception handling is to recover the program from the exception.

Run-time exception and non-run are 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.