PHP Trigger_error Trigger PHP Error Example _php tutorial

Source: Internet
Author: User

Example of PHP error triggered by Trigger_error in PHP


This article mainly introduces the PHP error triggered by the PHP trigger_error example, this article describes the error suppressor @ and through Trigger_error trigger PHP error example, the need for friends can refer to the following

Example of PHP error triggered by Trigger_error in PHP

"Error suppressor @"

In addition to the settings of error_reporting and display_errors in PHP.ini, the error_reporting () function, the Ini_set () function, you can also use the error suppressor @ Mask error output.

@ is added before any expression that produces an error.

"Triggering PHP errors via Trigger_error"

The ability to trigger errors is not limited to the PHP parser, but it can be triggered by the trigger_error () function, which, like an exception thrown in an exception, throws an error that can assist in debugging the code.

Cases

The code is as follows:

  

$num 1 = 1;

$num 2 = ' 2 ';

if (! ( Is_numeric ($num 1) && is_numeric ($num 2))) {

Manually throwing notification-level errors

Trigger_error (' Num1 and num2 must be a legal value ', e_user_notice);

}else{

echo $num 1 + $num 2;

}

Echo '
The program continues to execute downward ';

Output:

The code is as follows:

3

Program continues to execute down

and

The code is as follows:

  

$num 1 = 1;

$num 2 = ' 2a ';

if (! ( Is_numeric ($num 1) && is_numeric ($num 2))) {

Manually throwing notification-level errors

Trigger_error (' Num1 and num2 must be a legal value ', e_user_notice);

}else{

echo $num 1 + $num 2;

}

Echo '
The program continues to execute downward ';

Output:

The code is as follows:

( ! ) NOTICE:NUM1 and num2 must be valid values in D:\practise\php\Error\error1.php on line 6

Program continues to execute down

"Other" when a critical error such as a database connection is not up, you can manually throw an error-replace PHP's built-in e_warning warning with E_user_error.

http://www.bkjia.com/PHPjc/1020270.html www.bkjia.com true http://www.bkjia.com/PHPjc/1020270.html techarticle PHP error triggered by Trigger_error PHP example This article mainly describes the PHP trigger_error triggered by the PHP error example, this article describes the error suppressor @ and through the trigger_error touch ...

  • 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.