The writing of a program inevitably presents a variety of errors, so how can I handle these errors, or display errors so that we can find the changes? This uses the exception handling. Here we will introduce the concepts related to 5 exception handling.
PHP5 Exception Handling
PHP 5 adds exception handling modules similar to those in other languages. Exceptions generated in PHP code can be thrown by a throw statement and captured by a catch statement. The code that requires exception handling must be placed inside a try code block to catch possible exceptions.
Each try must have at least one catch corresponding to it. You can use multiple catches to catch exceptions that are generated by different classes. When the try code block no longer throws an exception or cannot find a catch that matches the thrown exception, the PHP code resumes execution after jumping to the last catch.
Of course, PHP5 exception handling allows you to throw (throw) exceptions again within a catch code block. When an exception is thrown, the code behind it (the code block where the exception was thrown) will not continue, and PHP will attempt to find the first catch to match it.
If an exception is not captured and does not use Set_exception_handler () for the appropriate processing, then PHP will produce a serious error and output uncaught exception ... (The exception is not caught) prompt information.
The properties and methods of exception class for PHP5 exception handling
The following code is only a description of the structure of the built-in exception-handling class, and it is not a meaningful piece of code available.
-
- Class exception{
- protected $ message = ' Unknown
Exception ';
- Exception information
- protected $ Code = 0 ;
- User-defined exception codes
- protected $file;
- The file name of the exception that occurred
- protected $line;
- The line number of the code where the exception occurred
- function __construct ($message =
NULL , $ Code = 0 );
- Final function getMessage ();
- Return exception information
- Final function GetCode ();
- Return exception code (codename)
- Final function getFile ();
- Returns the file name of the exception that occurred
- Final function getLine ();
- Returns the line number of the code where the exception occurred
- Final function gettrace ();
- BackTrace () array
- Final function gettraceasstring ();
- Gettrace () information that has been rasterized into a string
- Methods that can be overloaded
- function __tostring ();
- A string that can be output
- }
- ? >
The above is the analysis of PHP5 exception handling, I hope that the need for a friend to help.
http://www.bkjia.com/PHPjc/446145.html www.bkjia.com true http://www.bkjia.com/PHPjc/446145.html techarticle the writing of a program inevitably presents a variety of errors, so how can I handle these errors, or display errors so that we can find the changes? This uses the exception handling. ...