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. Examples of capturing and handling exceptions, 3. exception class... 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. Examples of capturing and handling exceptions, 3. getmessage (), 4. getfile (), a member function of the exception class () 5. getline (), 6, display warning or error messages, 7. Custom error handling functions for the exception class.
1. built-in exception handling class
2. example of capturing and handling exceptions
'; If (is_dir ('./test') {echo 'detects that ../ch16 is a directory'; echo'
'; Echo' other operations may be continued '; echo'
'; Echo'... '; echo'
';} Else {throw new exception ($ error, 12345);} echo' if the above throw exception occurs, this line of code will not be executed and the catch block will be executed in turn
';} Catch (exception $ e) {echo' catch an exception: '. $ e-> getmessage ()."
Error code: ". $ e-> getcode ().'
'; // Display $ error and 123456 echo'
';} Echo 'continue to execute';?>
3. getmessage (), a member function of the exception class ()
Getmessage (); echo'
================================='; Echo'
';} Echo' program execution completed ';?>
4. getfile (), a member function of the exception class ()
Getmessage (); echo'
'; Echo' error File: '. $ e-> getfile (); echo'
================================='; Echo'
';} Echo' program execution completed ';?>
5. getline (), a member function of the exception class ()
Getmessage (); echo'
'; Echo' error File: '. $ e-> getfile (); echo'
'; Echo' error row: '. $ e-> getline (); echo'
================================='; Echo'
';} Echo' program execution completed ';?>
6. display warning or error messages
7. Custom error handling functions.
"; Echo" program$ FileDuring execution$ LineLine to generate an error. "; Echo"
"; Echo" error code:$ CodeThe cause of the error is:$ Msg";} Echo $ uvar;?>
Link to this article:
Add to favorites ^ please keep the tutorial address.