Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

PHP: Trigger fatal error?

I would like to be able to throw a fatal, uncatchable error in my php class when a user of my class abuses it for something I did not intend. I don't want him/her to be able to recover with a catch clause. I know about trigger_error, but I can only make it issue warnings or notices.

like image 320
DudeOnRock Avatar asked Apr 08 '13 19:04

DudeOnRock


People also ask

How can I get fatal error in php?

You can "catch" these "fatal" errors by using set_error_handler() and checking for E_RECOVERABLE_ERROR. I find it useful to throw an Exception when this error is caught, then you can use try/catch.

How can I force error in php?

Use trigger_error() after you used set_error_handler() to register your own callback function which either logs or emails the error codes to you, and echo a simple friendly message to the user. trigger_error always reports the line and file that trigger_error was called on.

Why does this code trigger an error in php?

Definition and Usage. The trigger_error() function creates a user-level error message. The trigger_error() function can be used with the built-in error handler, or with a user-defined function set by the set_error_handler() function.

What is PHP error message?

Basically, an error is a mistake in a program that may be caused by writing incorrect syntax or incorrect code. An error message is displayed on your browser containing the filename along with location, a message describing the error, and the line number in which error has occurred.


1 Answers

E_USER_ERROR is the suited constant.

trigger_error("Fatal error", E_USER_ERROR); 

See also the first example of the manual page and the list of PHP Errors (only ones beginning with E_USER* may be issued from trigger_error).

like image 188
bwoebi Avatar answered Oct 05 '22 08:10

bwoebi