PHP capture global exception

PHP version 7 or catch the exception Throwable

index.php:

. 1 ? < PHP
 2  // close all error messages 
. 3  the error_reporting ( E_ALL );
 . 4  
. 5  the try {
 . 6    // the main.php inlet actual traffic scenario file 
. 7    require_once './main.php' ;
 . 8 } the catch (\ the Throwable E $ ) {
 . 9    // perform custom business requirements 
10    var_dump ( $ Exception -> the getMessage ());
 . 11 }

 

The following versions of PHP 7 using   set_error_handler  catch exceptions

<? PHP
 the error_reporting ( E_ALL );
 the set_error_handler ( 'the handle_error' );
 function the handle_error ( $ NO , $ MSG , $ File , $ Line ) {
 // perform custom business requirements 
}
 the try {
  require_once './main.php' ; 
} the catch (\ Exception  $ Exception ) {
  // implementation of custom business requirements 
} the catch (\ error $ error ) {
  // implementation of custom business requirements 
}

 

Guess you like

Origin www.cnblogs.com/yaomao/p/11260388.html