Exemplo n.º 1
0
 /**
  * Masks an exception with the called class. This should catch fatal and php errors.
  * It should always be followed by the unmask() method to remove the mask.
  * @param string $message Error message.
  * @param int $code Error code.
  * @return void
  */
 public static function mask($message = null, $code = 0)
 {
     $calledClass = get_called_class();
     $exception = new $calledClass($message, $code);
     ErrorHandler::applyMask($exception);
 }
Exemplo n.º 2
0
 /**
  * Captures and masks an exception inside an anonymous closure's code.
  * This is an equivalent of a try/catch block, but it can catch Fatal
  * and Php errors.
  * @param string $message Error message.
  * @param int $code Error code.
  * @param closure $closure Closure function containing code to execute.
  * @param array $params Parameters passed to the function as the first parameter.
  * @return mixed Returned value from the closure function.
  */
 public static function capture($message = null, $code = 0, $closure, $params = [])
 {
     $calledClass = get_called_class();
     $exception = new $calledClass($message, $code);
     ErrorHandler::applyMask($exception);
     $result = $closure($params);
     ErrorHandler::removeMask();
     return $result;
 }