Basically all integrated development environments provide powerful program debugging functions. When the program is compiled, connected, and run, errors in the program will be diagnosed. Program errors can be divided into three categories: syntax errors, operational errors and logical errors.
1. Syntax errors: These are caused by input that does not conform to grammatical rules during programming. For example: incomplete expressions, missing necessary punctuation marks, incorrect keyword input, mismatched data types, mismatched keywords in loop statements or selection statements, etc. Usually, when the compiler compiles a program, it will list the detected syntax errors in a prompt, also called compilation errors.
The debugging of syntax errors can be realized by the debugging function provided by the integrated development environment. When the program is compiled, the compiler will diagnose the syntax errors in the program. Compilation diagnostic syntax errors are divided into three categories: fatal errors, errors and warnings.
(1) Fatal error: This error is mostly an error that occurs within the compiler. When this type of error occurs, the compilation is forced to abort and the compiler can only be restarted. However, this type of error rarely occurs. In order to To be safe, it is best to save the program before compiling.
(2) Error: This error is usually caused by improper syntax during compilation. For example: brackets do not match, variables are not declared, etc. When this kind of error occurs, the compiler will display an error prompt. We can modify the source program according to the prompt. This type of error occurs the most.
(3) Warning: It means that the compiled program suspects that there is an error, but is not sure. Sometimes it can be forcibly passed. For example: the main function without void declaration has no return value, double data is converted to float type, etc. Some of these warnings will cause errors and some will pass.
2. Running errors: refers to errors that occur during the running of the program. For example: the divisor is 0 during division operation, the array subscript is out of bounds, the file cannot be opened, the disk space is insufficient, etc.
3. Logic error: After the program is run, the results expected by the designer are not obtained. This indicates that there is a logic error in the program. This error is syntactically valid but logically incorrect.
For 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. Often, logical errors will also produce runtime errors.
Under normal circumstances, when the compiler compiles a program, it cannot detect logical errors in the program, and it will not generate logical error prompts. Therefore, logical errors are difficult to eliminate, and the programmer needs to carefully analyze the program. , and with the help of the debugging tools provided by the integrated development environment, the cause of the error can be found and eliminated.
The above is the detailed content of What are the three categories of errors in programming?. For more information, please follow other related articles on the PHP Chinese website!