PHP is scheduled for two exception classes: Exception and Errorexception
The code is as follows:
Exception { /* Properties */ protected string $message; Exception message Content protected int $code; Exception code number protected string $file; The file name that throws the exception protected int $line; Throws the line number of the exception in the file /* Method */ Public __construct ([string $message = "" [, int $code = 0 [, Exception $previous = null]]) Final public string getMessage (void)//exception-thrown information Final public Exception getprevious (void)//Previous exception Final public int getcode (void)//exception code, which is user-defined Final public string getFile (void)//unexpected file path strength Final public int getLine (void)//The row where the exception occurred Final public array gettrace (void)//exception tracking information (array) Final public string gettraceasstring (void)//Exception tracking information (string) public string __tostring (void)//The return value of the child function is called when attempting to use the exception object as a string directly Final private void __clone (void)//Clone exception object when called }
The code is as follows:
Errorexception extends Exception {
/* Properties */ protected int $severity; /* Method */
Public __construct ([string $message = "" "[, int $code = 0 [, int $severity = 1 [, String $filename = __file__ [, int $li Neno = __line__ [, Exception $previous = NULL]] []]) Final public int getseverity (void) /* Inherited method */ Final public string exception::getmessage (void) Final public Exception exception::getprevious (void) Final public int exception::getcode (void) Final public string exception::getfile (void) Final public int exception::getline (void) Final public array exception::gettrace (void) Final public string exception::gettraceasstring (void) public string exception::__tostring (void) Final private void exception::__clone (void) }
So how do I catch an exception?
(1) PHP available try...catch ... To catch an exception, the code for exception handling must be inside a try code block.
You can see that the exception is handled using the Ser_exception_handler callback function, and subsequent code does not continue, but Try-catch can. (3) PHP can catch different types of exceptions with multiple catch and allow the exception to be thrown again within the catch code block.
The code is as follows:
Please extend the exception class according to the actual Class MyException extends Exception { Public function __construct ($message = ", $code = 0) {
}
Public Function myFunction () { Echo ' Just for test '; } }
The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion;
products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the
content of the page makes you feel confusing, please write us an email, we will handle the problem
within 5 days after receiving your email.
If you find any instances of plagiarism from the community, please send an email to:
info-contact@alibabacloud.com
and provide relevant evidence. A staff member will contact you within 5 working days.