Home  >  Article  >  Backend Development  >  PHP custom error handling function trigger_error()_PHP tutorial

PHP custom error handling function trigger_error()_PHP tutorial

WBOY
WBOYOriginal
2016-07-21 15:12:301029browse

Definition and Usage The trigger_error() function creates a user-defined error message.
trigger_error() is used to trigger an error message under user-specified conditions. It is used with the built-in error handler or with user-defined functions created with the set_error_handler() function.

If an illegal error type is specified, this function returns false, otherwise it returns true.
Syntax trigger_error(error_message,error_types)
Parameter description error_message is required. Specifies the error message. Length limit is 1024 characters. error_types are optional. Specifies the error type of the error message. Possible values: •E_USER_ERROR
•E_USER_WARNING
•E_USER_NOTICE

Copy code The code is as follows:

< ?php
function myError($errno,$errstr,$errfile,$errline){
switch($errno){
case E_USER_ERROR:
echo "My ERROR";
echo "Fatal error in line $errline of file $errfile";
exit(1);
break;
case E_USER_WARNING:
echo "My WARNING [$errno] $errstr";
break;
default:
echo "Unknown error type:[$errno] $errstr";
break;
}
}
set_error_handler("myError");
$age=-100;
if($age<0){
trigger_error('age you input must>=0',E_USER_ERROR);
}
?>

www.bkjia.comtruehttp: //www.bkjia.com/PHPjc/326714.htmlTechArticleDefinition and Usage The trigger_error() function creates a user-defined error message. trigger_error() is used to trigger an error message under user-specified conditions. It works with the built-in error handler...
Statement:
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn