Trigger_error in PHP: trigger_errorphp

Source: Internet
Author: User
Tags php error

Trigger_error in PHP: trigger_errorphp

Example of a PHP error triggered by 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]

Copy codeThe 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 '<br/> the program continues to run downward ';

Output:
Copy codeThe Code is as follows:
3
Program continues to run down

And:
Copy codeThe 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 '<br/> the program continues to run downward ';

Output:
Copy codeThe 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.