The trigger_error() function creates a user-defined error message.
The trigger_error() function is used to trigger an error message under user-specified conditions. It can be used with the built-in error handler, or with a user-defined function set by the set_error_handler() function. This function is useful when you need to customize an error message under a specified condition when running a script.
If an illegal error type is specified, this function returns FALSE, otherwise it returns TRUE.
trigger_error(error_message,error_types)
parameter | describe |
---|---|
error_message | Required. Specifies the error message. Length limit is 1024 characters. |
error_types | Optional. Specifies the error type of the error message. Possible error types: E_USER_ERROR - A fatal user-generated runtime error. Unrecoverable error. Stop executing the script. E_USER_WARNING - User-generated non-fatal warning at runtime. The script did not stop executing. E_USER_NOTICE - Default. User-generated runtime notifications. Script discovery can be a bug, but can also occur when the script is running normally. |
<?php$test=2;if ($test>1){trigger_error("A custom error has been triggered");}?>
The output of the above code looks like this:
Notice : A custom error has been triggered in C:webfoldertest.php on line 6