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