Home > Java > JavaBase > What are the types of errors in java?

What are the types of errors in java?

王林
Release: 2019-11-13 15:45:40
Original
10640 people have browsed it

What are the types of errors in java?

Program errors can be abstractly divided into three categories: grammatical errors, operational errors and logical errors.

1. Syntax errors

are caused by input that does not conform to grammatical rules during programming. The program cannot be compiled and the program cannot be run. This type of error is the simplest and easier to debug.

Example:

The expression is incomplete, the necessary punctuation is missing, the keyword is entered incorrectly, the data type does not match, the keyword of the loop statement or selection statement is incorrect. Match etc. Usually, when the compiler compiles a program, it will list the detected syntax errors in a prompt, also called compilation errors.

Solution:

The debugging of syntax errors can be achieved by the debugging function provided by the integrated development environment. When the program is compiled, the compiler will Diagnose syntax errors in .

2. Running errors

refers to errors that occur during the running of the program. The program passes syntax error detection, but an error occurs during running, causing the program to be forced to terminate. Such errors have specific occurrence conditions, so the faulty code segment can be accurately located, making debugging more convenient.

Example:

The divisor during division operation is 0, the array subscript is out of bounds, the file cannot be opened, the disk space is not enough, the database connection error, etc.

Solution:

When such errors occur, the compilation platform will generally prompt corresponding information. For regular errors, there will be more precise prompts, but sometimes The cause of the error prompted will be relatively vague, but because this type of error generally occurs only under specific conditions when the program is running, so based on the conditions under which the error occurs, the code section of the program error can be roughly determined, and combined with the cause of the error, It can also make debugging errors easier.

3. Logic error

After the program is run, the results expected by the designer are not obtained, which means that there is a logic error in the program. This error is syntactically valid but logically incorrect.

Example:

Incorrect variables are used, the order of instructions is wrong, the conditions of the loop are incorrect, the programming algorithm is not fully considered, etc.

Solution:

Usually, logic errors will also produce runtime errors. Under normal circumstances, when the compiler compiles a program, it cannot detect logic errors in the program, and will not generate logic error prompts. Therefore, logic errors are difficult to eliminate. Programmers need to carefully analyze the program and use an integrated development environment. Only with the provided debugging tools can we find the cause of the error and eliminate it.

Recommended tutorial: Java tutorial

The above is the detailed content of What are the types of errors in java?. 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