Home > Article > Backend Development > php predefined exception
1.Exception
(PHP 5 >= 5.1.0)
Introduction
Exception is the base class of all exceptions.
Method
Exception::__construct — Exception constructor
Exception::getMessage — Get the exception message content
Exception::getPrevious — Return the previous exception in the exception chain
Exception::getCode — Get the exception code
Exception::getFile — Get the name of the program file where the exception occurred
Exception::getLine — Get the line number of the code in the file where the exception occurred
Exception::getTrace — Get the exception tracking information
Exception::getTraceAsString — Get Exception tracking information of string type
Exception::__toString — Convert exception object to string
Exception::__clone — Exception cloning
2.ErrorException
(PHP 5 >= 5.1.0)
Introduction
Error exception.
Example
Example #1 Use the set_error_handler() function to host error information to ErrorException
<?php function exception_error_handler($errno, $errstr, $errfile, $errline ) { throw new ErrorException($errstr, 0, $errno, $errfile, $errline); } set_error_handler("exception_error_handler"); /* Trigger exception */ strpos(); ?>
The output of the above routine is similar to:
Fatal error: Uncaught exception 'ErrorException' with message 'Wrong parameter count for strpos()' in /home/bjori/tmp/ex.php:8 Stack trace: #0 [internal function]: exception_error_handler(2, 'Wrong parameter...', '/home/bjori/php...', 8, Array) #1 /home/bjori/php/cleandocs/test.php(8): strpos() #2 {main} thrown in /home/bjori/tmp/ex.php on line 8
method
ErrorException::__construct — exception constructor
ErrorException::getSeverity — Get exception severity