Error handling:
1. Syntax errors
2. Run-time errors
3. Logic Error
Error Reporting:
Fatal error E_error
Warning E_warning
Note E_notice
Development phase: Output all error reports at development time, enabling us to debug
Run phase: Do not let the program output any kind of error reporting
To write error reports to the log
I. Specifying error Reporting Error_reporting=e_all (in Php.inn)
Two. Turn off error output Display_errors=off (in php.ini)
Three. Turn on the error log function Log_errors=on (in php.ini)
1. By default, if you do not specify an error log location, the log is written to the Web server by default
2. Specify a file name for the Error_log option, which is the error log
3. Write to the operating system log Error_log=syslog
<?PHP//Note and warning do not terminate the program's operation, but the error terminates the program's Operation/*Error E_error warning e_warning Note E_notice*///all errors are output except for attentionerror_reporting(E_all& ~E_notice);//set the value of the profile (temporary)//ini_set ("Upload_max_filesize", 2000000000),//Get the value of the configuration file//ini_get ("Upload_max_filesize");// Turn off the display of error reports, which are typically used during the run phaseIni_set("Display_errors", "Off");//to write error reports to the logIni_set("Log_errors", "on");//Directory of LogsIni_set("Error_log", "D:/error.log");GetType($var);//NoteGetType();//warning//getype (); Error, program terminationEcho"############<br>";?>
Exception handling: Accidental, unexpected events that occur during program operation, using exceptions to change script normal process
A new and important feature in PHP5
try{
}catch (Exception object) {
}
1. If the code in the try does not have a problem, the execution of the code in try is done after the catch is executed
2. If the code in the try has an exception, throws an exception object (using throw), throws the parameter in the catch, the content after the exception code in the try is not executed, jumps directly into the catch to execute, the catch executes, and then continues to execute down
<?PHPTry{ Echo"11111111<br>"; $file[Email protected]fopen("./hello.txt", "R"); if(!$file){ Throw New Exception("File open Failed"); } Echo"2222222222<br>";}Catch(Exception $e){ Echo"3333333<br>"; Echo $e->getmessage (). " <br> "; Touch("Hello.txt"); $file[Email protected]fopen("./hello.txt", "R");}Echo"4444444<br>";?>
Error handling and exception handling in PHP