PHP Trigger_error Trigger PHP Error example, trigger_errorphp
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
Copy the Code code as follows:
<?php
$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:
Copy the Code code as follows:
3
Program continues to execute down
and
Copy the Code code as follows:
<?php
$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:
Copy the Code code 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/1021092.html www.bkjia.com true http://www.bkjia.com/PHPjc/1021092.html techarticle PHP trigger_error Trigger PHP error example, trigger_errorphp php through Trigger_error trigger PHP error Example "error suppressor @" In addition to php.ini error_reporting and Displ ...