Example of a PHP error triggered by trigger_error in PHP

Source: Internet
Author: User
This article describes how to trigger a PHP error through trigger_error in PHP. This article describes the error blocker @ and the example of triggering a PHP error through trigger_error, for more information, see trigger_error in PHP.

[Error blocker @]

In addition to setting error_reporting and display_errors, error_reporting (), and ini_set () functions in php. ini, you can also use the error blocker @ to block error output.

@ Before any expression that produces an error.

[Trigger_error triggers PHP errors]

The function of triggering an error is not limited to the PHP parser, but can also be used to trigger an error through the trigger_error () function. similar to an exception thrown in an exception, an error is thrown to help debug the code.

[Example]

The code is as follows:


<? Php
$ Num1 = 1;
$ Num2 = '2 ';
If (! (Is_numeric ($ num1) & is_numeric ($ num2 ))){
// Manually throw a notification-level error
Trigger_error ('num1 and num2 must be valid number', E_USER_NOTICE );
} Else {
Echo $ num1 + $ num2;
}

Echo'
Program continues to run down ';

Output:

The code is as follows:


3
Program continues to run down


And:

The code is as follows:


<? Php
$ Num1 = 1;
$ Num2 = '2a ';
If (! (Is_numeric ($ num1) & is_numeric ($ num2 ))){
// Manually throw a notification-level error
Trigger_error ('num1 and num2 must be valid number', E_USER_NOTICE );
} Else {
Echo $ num1 + $ num2;
}

Echo'
Program continues to run down ';

Output:

The code is as follows:


(! ) Notice: num1 and num2 must be valid values in D: \ practice \ php \ Error \ error1.php on line 6


Program continues to run down

[Others] when the database cannot be connected and other serious errors, you can manually throw an error -- replace PHP's built-in E_WARNING warning with E_USER_ERROR.

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.