1, built-in exception handling class.
2. Examples of capturing and handling exceptions.
3, the member function of the Exception class GetMessage ().
4, the member function of the Exception class GetFile ().
5, the member function of the Exception class Getline ().
6, display warning or error message.
7, custom error handling function.
*/
1, built-in exception handling class.
| The code is as follows |
Copy Code |
|
Class exception
{
protected $message = ' Unknown exception '; Exception information
protected $code = 0; User-defined exception codes
protected $file; Name of the exception that occurred
protected $line; 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
Final function getfile (); //Returns the filename of the exception that occurred
final function getline (); //Return the code line number where the exception occurred
final function gettrace (); //BackTrace () array
final function gettraceasstring (); //Gettrace () information that has been formatted as a string
function __tostring (); A string that can be exported
}
|
2. Examples of capturing and handling exceptions.
| The code is as follows |
Copy Code |
|
Try
{
$error = ' Throw exception information and jump out of Try block <br/> ';
if (Is_dir ('./test '))
{
Echo ' detects that. /CH16 is a catalogue ';
Echo ' <br/> ';
Echo ' may continue to do some other action ';
Echo ' <br/> ';
echo ' ... ';
Echo ' <br/> ';
}
Else
{
throw new Exception ($error, 12345);
}
Echo ' Above throw exception, this line of code does not execute, instead executes catch block <br/> ';
}
catch (Exception $e)
{
Echo ' catches exception: '. $e->getmessage (). "<br/> Error code:". $e->getcode (). ' <br/> '; Show $error and 123456
Echo ' <br/> ';
}
Echo ' continued execution ';
|