in PHP, exception handling mechanisms are limited, cannot automatically throw exceptions, must be done manually, and built-in exceptions are limited.
PHP takes a number of exceptions as errors, so that they can be taken over by Set_error_handler as if they were errors, and then actively throwing exceptions.
For example, the following Warning types of errors are not captured: Warning:division by the Zero in
1 Try {2 $a = 5/03 }catch (Exception$e) {4 echo ' error message: ',$e-GetMessage (); 5 }
Use Set_error_handler to take over PHP error handling, catch exceptions and non-fatal errors
1 functionCustomerror ($errno,$errstr,$errfile,$errline){2 Throw New Exception(' Number of error rows '.$errline.‘ Line | '.$errstr);3 }4 Set_error_handler("Customerror",E_all);5 6 Try{7 $a= 5/0;//warning:division by Zero in8}Catch(Exception $e){9 Echo' Error message: ',$e-getMessage ();Ten}
This scenario typically exists in the framework of the custom error handling mechanism, making the experience of error messages more visible.
Error handling mechanism in PHP