Error handling mechanism in PHP

Source: Internet
Author: User

Common three types of errors:

1.Notice: Notification error, minimum error, when a notification error occurs, a message pops up. Execution of code is not interrupted.

Error code:

#例如
inch 2

2.Warning: Warning error, when a warning error occurs, a warning message pops up and he does not interrupt the program to run down.

inch 2

3.Error: Fatal error, when a fatal error occurs, a fatal error message pops up, interrupting program execution.

inch 2

The above is common in PHP 3 errors, with more detailed error see the following code:

#查看更多错误, you can call the system function get_defined_constants This function # A brief answer: Echo"<pre>"; Var_dump (Get_defined_constants ()); Array (1326) {  ["E_error"]=>int(1)  ["E_recoverable_error"]=>int(4096)  ["e_warning"]=>int(2)  ["E_parse"]=>int(4)  ["E_notice"]=>int(8)  ["e_strict"]=>int(2048)  ["e_deprecated"]=>int(8192)  ["E_core_error"]=>int( -)  ["e_core_warning"]=>int( +)  ["E_compile_error"]=>int( -)  ["e_compile_warning"]=>int( -)  ["E_user_error"]=>int( the)  ["e_user_warning"]=>int( +)  ["E_user_notice"]=>int(1024x768)  ["e_user_deprecated"]=>int(16384)  ["E_all"]=>int(32767)  ["Debug_backtrace_provide_object"]=>int(1)  ["Debug_backtrace_ignore_args"]=>int(2)  ["TRUE"]=>BOOL(true)  ["FALSE"]=>BOOL(false)  ["NULL"]=>];~ ~ ~ There's more.

Incorrect triggering:

Can be divided into two types:

1. Automatic system triggering

The system automatically checks the compilation and execution of the program, and automatically gives the error prompt when an error occurs.

2. Manual Trigger:

Manual triggering in PHP can invoke system functions, which are generally used to debug the corresponding error program, which is generally a user-level error.

triggered function: Trigger_error

The first parameter can set the error message, the second parameter can set the wrong level

E_user_notice: Trigger notification level error, lowest level user error

E_user_warning: Error triggering warning level, subsequent code continues execution

E_user_error: A fatal error level error is triggered and subsequent code terminates execution.

Error display switch:

Configure the Display_errors option in php.ini, default to On, display error prompts, and suggest setting on during development to facilitate project debugging. Product on-line set to OFF, the user experience is good, security is high, this setting has been effective.

You can also execute the Ini_set function in the script, set the value of the dispaly_errors, only in the script life cycle, cannot modify the php.ini file, you can take that way, the end of the script cycle, option recovery.

Set the level of error display:

After you set the level of error reporting, you can decide what level of error information to display.

Configure the error_reporting option in PHP.ini, which is set to show all errors by default:

After you set the level of error reporting, you can decide what level of error information to display.

E_all: Show All Errors

E_notice: Display of notification-based errors

E_waring: Displaying warning errors

E_error: Displaying fatal errors

You can also call the Ini_set function setting.

Error log:

Error log settings:
General project on-line log error logs are required to check for system errors, and the default log switch is turned on.

Default path for error log

Apache:

Apache/logs/error.log

Nginx:

/var/log/nginx/error.log

Custom error Log Store path:
Ini_set (' error_log ', ' path ');

Can only be set once valid, the end of the script life cycle, the end of the record.

Custom Error Handling Processor:

When an error occurs, the system's error handling mechanism is used by default to prompt for error messages, to indicate what level of error, error message string, error file, and line number.

You can customize the Setup error prompt:

Write a custom error handling function

My_error

There are four parameters

$errCode: Error code

$ERRSTR: Error message

$errFile: Error file

$errLine: Error line number

The default is not called and you must call the Set_error_handler function to set the function to be called automatically by the system.

First come to this, welcome to continue to add ~ ~ ~, I meng199898, reprint need to note

Error handling mechanism in PHP

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.