亚洲国产日韩欧美一区二区三区,精品亚洲国产成人av在线,国产99视频精品免视看7,99国产精品久久久久久久成人热,欧美日韩亚洲国产综合乱

PHP 7 error handling

PHP 7 changes the way most errors are reported. Unlike PHP 5's traditional error reporting mechanism, most errors are now thrown as Error exceptions.

This kind of Error exception can be caught by try / catch block like a normal exception. If there is no matching try / catch block, the exception handling function (registered by set_exception_handler()) is called for processing. If an exception handler has not been registered, it is handled in the traditional way: it is reported as a Fatal Error.

The Error class does not extend from the Exception class, so code such as catch (Exception $e) { ... } cannot catch Error. You can use code like catch (Error $e) { ... } or register an exception handler (set_exception_handler()) to catch Error.

Error Exception Hierarchy

  • Error
    • ArithmeticError
    • AssertionError
    • DivisionByZeroError
    • ParseError
    • ##TypeError
  • ##Exception
    • ...

1458887252-2773-exception-hiearchy.jpg##Instance

<?php 
class MathOperations  
{ 
   protected $n = 10; 

   // 求余數(shù)運(yùn)算,除數(shù)為 0,拋出異常 
   public function doOperation(): string 
   { 
      try { 
         $value = $this->n % 0; 
         return $value; 
      } catch (DivisionByZeroError $e) { 
         return $e->getMessage(); 
      } 
   } 
} 

$mathOperationsObj = new MathOperations(); 
print($mathOperationsObj->doOperation()); 
?>

Above The output result of program execution is:

Modulo by zero
Continuing Learning
||
<?php class MathOperations { protected $n = 10; // 求余數(shù)運(yùn)算,除數(shù)為 0,拋出異常 public function doOperation(): string { try { $value = $this->n % 0; return $value; } catch (DivisionByZeroError $e) { return $e->getMessage(); } } } $mathOperationsObj = new MathOperations(); print($mathOperationsObj->doOperation()); ?>
submitReset Code