Home Backend Development PHP Tutorial PHP 自定义错误处理函数trigger_error()_php技巧

PHP 自定义错误处理函数trigger_error()_php技巧

May 17, 2016 am 09:06 AM
Custom function mistake

定义和用法trigger_error() 函数创建用户定义的错误消息。
trigger_error() 用于在用户指定的条件下触发一个错误消息。它与内建的错误处理器一同使用,也可以与由 set_error_handler() 函数创建的用户自定义函数使用。

如果指定了一个不合法的错误类型,该函数返回 false,否则返回 true。
语法trigger_error(error_message,error_types)
参数描述error_message必需。规定错误消息。长度限制为 1024 个字符。error_types可选。规定错误消息的错误类型。 可能的值: •E_USER_ERROR
•E_USER_WARNING
•E_USER_NOTICE

复制代码 代码如下:

function myError($errno,$errstr,$errfile,$errline){
switch($errno){
case E_USER_ERROR:
echo "My ERROR[$errno] $errstr
";
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($agetrigger_error('age you input must>=0',E_USER_ERROR);
}
?>
Statement of this Website
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

Hot Article Tags

Notepad++7.3.1

Notepad++7.3.1

Easy-to-use and free code editor

SublimeText3 Chinese version

SublimeText3 Chinese version

Chinese version, very easy to use

Zend Studio 13.0.1

Zend Studio 13.0.1

Powerful PHP integrated development environment

Dreamweaver CS6

Dreamweaver CS6

Visual web development tools

SublimeText3 Mac version

SublimeText3 Mac version

God-level code editing software (SublimeText3)

Unable to complete operation (Error 0x0000771) Printer error Unable to complete operation (Error 0x0000771) Printer error Mar 16, 2024 pm 03:50 PM

Unable to complete operation (Error 0x0000771) Printer error

Revealing the causes of HTTP status code 460 Revealing the causes of HTTP status code 460 Feb 19, 2024 pm 08:30 PM

Revealing the causes of HTTP status code 460

Windows Sandbox startup failed - Access Denied Windows Sandbox startup failed - Access Denied Feb 19, 2024 pm 01:00 PM

Windows Sandbox startup failed - Access Denied

Solve the errors encountered when installing autocad in win11 Solve the errors encountered when installing autocad in win11 Dec 30, 2023 pm 03:23 PM

Solve the errors encountered when installing autocad in win11

Solution to Windows Update prompt Error 0x8024401c error Solution to Windows Update prompt Error 0x8024401c error Jun 08, 2024 pm 12:18 PM

Solution to Windows Update prompt Error 0x8024401c error

The server encountered an error, 0x80070003, while creating a new virtual machine. The server encountered an error, 0x80070003, while creating a new virtual machine. Feb 19, 2024 pm 02:30 PM

The server encountered an error, 0x80070003, while creating a new virtual machine.

Resolve code 0xc000007b error Resolve code 0xc000007b error Feb 18, 2024 pm 07:34 PM

Resolve code 0xc000007b error

Fix Pioneer Error Code Kadena-Keesler Fix Pioneer Error Code Kadena-Keesler Feb 19, 2024 pm 02:20 PM

Fix Pioneer Error Code Kadena-Keesler

See all articles