Home>Article>Backend Development> What is error handling in PHP? Error code? Wrong trigger?

What is error handling in PHP? Error code? Wrong trigger?

慕斯
慕斯 Original
2021-06-15 16:28:58 2261browse

The previous article introduced you to "What are the two article loading paths in PHP? What is the file path?》, this article continues to introduce to you what is error handling in PHP? Error code? Wrong trigger? It has certain reference value. Friends in need can refer to it. I hope it will be helpful to everyone.

What is error handling in PHP? Error code? Wrong trigger?

Error handling:

refers to when the system (or user) executes certain codes , if an error is found, the programmer will be notified through

error handling.

Error classification:

1) Syntax error: The code written by the user does not comply with PHP's syntax specifications. Syntax errors will cause the code to fail during the compilation process, so The code will not execute (Parseerror).

2) Runtime error: The code is compiled successfully, but during the execution of the code there will be errors (runtime error) caused by unsatisfied conditions.

3) Logic errors: The programmer was not standardized enough when writing the code, and some logical errors occurred, causing the code to execute normally, but not getting the desired results,

$a= 10; If(Sa= 1){ //最常见把比较符号写成赋值符号 //执行代码。

Error code:

All error codes seen are defined as system constants in PHP (can be used directly).

1) System error:.

E_ PARSE: Compilation error, code will not be executed.

E_ ERROR: fatal error, a fatal error, will cause the code to not continue to execute correctly (break at the error location).

E_ WARNING: warning, warning error, will not affect code execution, but may get unexpected results.

E_ _NOTICE: notice, notification error, will not affect code execution.

2) User error:

E_ _USER ERROR,

E_ USER_ WARNING,

E_ _USER_ _NOTICE.

The error code the user will use when using a custom error trigger (the system will not use it).

3) Others:

E _ALL, which represents all slave errors (usually used more during error control), it is recommended that during the development process ( development environment).

All error constants (code names) starting with E are actually stored in one byte, and then each error occupies a bit corresponding to

. If you want to make some errors The control can be operated using bit operations.

Exclude notification level notice: E_ ALL& ~E_NOTICE.

Only warnings and notifications: E_ WARNING | E_ NOTICE.

Error trigger:


    Triggered when the program is running: The system automatically compares the corresponding error information after an error occurs and outputs it to the user: mainly for syntax errors and runtime errors in the code.
  • Human triggering: Knowing that some logic may go wrong, use the corresponding judgment code to trigger a response error prompt.
  • Recommended learning: "
PHP Video Tutorial

"

The above is the detailed content of What is error handling in PHP? Error code? Wrong trigger?. For more information, please follow other related articles on the PHP Chinese website!

Statement:
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