PHP Exception handling class, PHP exception handling
PHP has many exception handling classes, where exception is the base class for all exception handling.
Exception has several basic properties and methods, including the following:
Message content for exception messages
Code exception Codes
File name that throws an exception
Line throws an exception in the number of lines of the file
Among the methods commonly used are:
Gettrace getting exception tracking information
Gettraceasstring string that gets the exception trace information
GetMessage getting error messages
If necessary, you can create a custom exception-handling class by inheriting the exception class.
Custom exception class, inherited PHP exception base class Exceptionclass MyException extends Exception { function getInfo () { return ' custom error message '; }} The try { //function that uses the exception should be in the "try" code block. If no exception is triggered, the code will continue to execute as usual. However, if an exception is triggered, an exception is thrown. throw new MyException (' Error ');//This specifies how to trigger an exception. Note: Each "throw" must correspond to at least one "catch", which can of course correspond to multiple "catch"} catch (Exception $e) {//"catch" code block catches an exception and creates an object containing the exception information Echo $e- >getinfo ();//Gets the custom exception information echo $e->getmessage ();//Gets GetMessage information inherited from the base class}
http://www.bkjia.com/PHPjc/963547.html www.bkjia.com true http://www.bkjia.com/PHPjc/963547.html techarticle PHP exception handling class, PHP exception handling PHP has a lot of exception handling classes, where exception is the base class for all exception handling. Exception has several basic properties and methods, including the following: ...