Home > Java > Javagetting Started > body text

What is the difference between Error and Exception in java

王林
Release: 2020-07-31 15:57:24
forward
2626 people have browsed it

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!

Related labels:
source:csdn.net
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template