Home  >  Article  >  Java  >  What is the difference between Error and Exception in java

What is the difference between Error and Exception in java

王林
王林forward
2020-07-31 15:57:242636browse

What is the difference between Error and Exception in java

The difference analysis is as follows:

Error: Errors that the program should not catch should be handed over to the JVM for processing. Generally may refer to very serious errors. We generally cannot get this error and cannot handle it!

(Recommended tutorial: java introductory tutorial)

Exception: Error that should be caught in the program. This exception class and its subclasses are what we need to learn to handle.

(1) RuntimeException: Runtime exception, also called unchecked exception, is a subclass of Exception, but does not need to be caught as an exception superclass. However, when an exception actually occurs, it will still cause the program to stop running. , but no error is reported during compilation. For example, the divisor is zero, the array null pointer, etc., these will only report errors after running.

Such exceptions can be handled or not handled, and can be avoided.

(Video tutorial recommendation: java video tutorial)

(2) Among all subclasses of Exception, except the RuntimeException class and its subclasses, other classes are It is called non-runtime exception, or checked exception. It is usually defined as the Checked class. It is necessary to handle possible exceptions, otherwise the compilation will report an error.

The Checked class mainly includes: exceptions of IO class and SQL class. When using these, exceptions must be handled first (captured using throws or try catch).

The above is the detailed content of What is the difference between Error and Exception in java. For more information, please follow other related articles on the PHP Chinese website!

Statement:
This article is reproduced at:csdn.net. If there is any infringement, please contact admin@php.cn delete