Php error handling and exception handling methods and example tutorial (12 ). Php error handling and exception handling methods and instance tutorials in program development, error handling is very important. today this article will tell him about php development, error handling function php error handling and exception handling methods and instance tutorials in program development, error handling is very important. today this article will tell him about php development, the error handling function also provides examples to illustrate the importance of error handling.
Php Tutorial error handling and exception handling methods and examples
In program development, error handling is very important. today this article tells him about the importance of error processing functions in php development and provides examples.
1. built-in exception handling class.
2. example of capturing and handling exceptions.
3. getmessage (), a member function of the exception class ().
4. getfile (), a member function of the exception class ().
5. getline (), a member function of the exception class ().
6. a warning or error message is displayed.
7. Custom error handling functions.
*/
// 1. built-in exception handling class.
Class exception
{
Protected $ message = 'unknown exception'; // exception information
Protected $ code = 0; // custom exception code
Protected $ file; // file name with an exception
Protected $ line; // The code line number with an exception
Function _ construct ($ message = null, $ code = 0 );
Final function getmessage (); // returns exception information
Final function getcode (); // returns the exception code
Final function getfile (); // returns the file name with an exception
Final function getline (); // return the code line number in which an exception occurs.
Final function gettrace (); // backtrace () array
Final function gettraceasstring (); // gettrace () information formatted as a string
Function _ tostring (); // output string
}
// 2. example of capturing and handling exceptions.
Try
{
$ Error = 'throws exception information and jumps out of the try block.
';
If (is_dir ('./test '))
{
Echo '../ch16 is a directory ';
Echo'
';
Echo 'other operations may be continued ';
Echo'
';
Echo '....';
Echo'
';
}
Else
{
Throw new exception ($ error, 12345 );
}
Echo 'the above throw exception, this line of code will not be executed, and then execute catch block
';
}
Catch (exception $ e)
{
Echo 'capture exception: '. $ e-> getmessage ()."
Error code: ". $ e-> getcode ().'
'; // Display $ error and 123456
Echo'
';
}
Echo 'continue execution ';
1 2
Http://www.bkjia.com/PHPjc/632056.htmlwww.bkjia.comtruehttp://www.bkjia.com/PHPjc/632056.htmlTechArticlephp error handling and exception handling methods and instance tutorials in program development, error handling is very important, today this article will tell him about in php Development, error handling letter...