Home > Java > javaTutorial > body text

Java exception types

(*-*)浩
Release: 2019-12-17 15:04:59
Original
2916 people have browsed it

Exceptions are some errors in the program, but not all errors are exceptions, and errors can sometimes be avoided.

Java exception types

For example, if your code is missing a semicolon, the result will be an error java.lang.Error; If you use System.out.println(11/0), then because you divide by 0, a java.lang.ArithmeticException exception will be thrown. (Recommended learning: java course)

There are many reasons for exceptions, which usually include the following categories:

The user has entered illegal data .

The file to be opened does not exist.

The connection is interrupted during network communication, or the JVM memory overflows.

Some of these exceptions are caused by user errors, some are caused by program errors, and others are caused by physical errors. -

To understand how Java exception handling works, you need to master the following three types of exceptions:

Checked exceptions:Most The most representative checked exceptions are exceptions caused by user errors or problems that cannot be foreseen by the programmer. For example, when trying to open a file that does not exist, an exception occurs. These exceptions cannot be simply ignored at compile time.

Run-time exceptions: Run-time exceptions are exceptions that may be avoided by the programmer. In contrast to checked exceptions, runtime exceptions can be ignored at compile time.

Error: An error is not an exception, but a problem out of the programmer's control. Errors are often ignored in code. For example, when the stack overflows, an error occurs that cannot be checked during compilation.

The above is the detailed content of Java exception types. For more information, please follow other related articles on the PHP Chinese website!

Related labels:
source:php.cn
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