国产av日韩一区二区三区精品,成人性爱视频在线观看,国产,欧美,日韩,一区,www.成色av久久成人,2222eeee成人天堂

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ù)運算,除數(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ù)運算,除數(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