Recently learned the next PHP7 new features tutorial, recorded some study notes.
PHP 7 Changes the way most errors are reported. Unlike the traditional error reporting mechanism of PHP 5, most errors are now thrown as error exceptions.
This error exception can be captured as a normal exception by the Try/catch block. If there is no matching try/catch block, the exception handler is called (registered by Set_exception_handler ()) for processing. If the exception handler has not been registered, it is handled in the traditional way: it is reported as a fatal error (Fatal error).
The error class is not extended from the Exception class, so the code with catch (Exception $e) {...} does not catch the error. You can catch the error with try{} catch (Error $e) {...}, or by registering the exception handler (Set_exception_handler ()).
Error Exception Hierarchy
Errorarithmeticerrorassertionerrordivisionbyzeroerrorparseerrortypeerrorexception ...
Instance
<?PHPclassmathoperations {protected $n= 10; //find remainder operation, divisor is 0, throw exception Public functionDooperation ():string { Try { $value=$this->n% 0; return $value; } Catch(Divisionbyzeroerror$e) { return $e-GetMessage (); } } } $MATHOPERATIONSOBJ=Newmathoperations (); Print($MATHOPERATIONSOBJ-dooperation ()); ?>
The above program execution output results are:
Modulo by Zero
Reproduced from the technology to bring you closer to me, original address: http://coderschool.cn/1749.html
PHP7 Error Handling