PHP error trapping process

PHP error trapping process


 

The method is generally used to trap the error:

try{
  ...
}catch(Exception $e){
  echo $e->getMessage();
}

or

set_exception_handler(function ($exception) {
  echo $exception->getMessage();
});

Example:

<?php

function Test () {
     the throw  new new  Exception ( "Parameter error" );
}

the try {
     // if the catch is not captured, will perform here 
    set_exception_handler ( function ( $ Exception ) {
         echo  $ Exception ; // Exception 'Exception' with the Message 'parameter error' in / www / web / ... ( a heap information) 
        echo '<br>' ;
         echo  $ Exception -> the getMessage (); // parameter error 
    });

    test();
} The catch ( Exception  $ E ) {
     echo  $ E -> the getMessage (); // Parameter error 
}

set_exception_handler - Set User-defined exception handler, try / catch block to capture the exception of no use for.


 

Guess you like

Origin www.cnblogs.com/gyfluck/p/11008260.html