yii\base\ErrorHandler::convertExceptionToError PHP Method

convertExceptionToError() public static method

This method can be used to convert exceptions inside of methods like __toString() to PHP errors because exceptions cannot be thrown inside of them.
public static convertExceptionToError ( Exception $exception )
$exception Exception the exception to convert to a PHP error.
    public static function convertExceptionToError($exception)
    {
        trigger_error(static::convertExceptionToString($exception), E_USER_ERROR);
    }

Usage Example

Beispiel #1
0
 /**
  * PHP magic method that returns the string representation of this object.
  * @return string the string representation of this object.
  */
 public function __toString()
 {
     // __toString cannot throw exception
     // use trigger_error to bypass this limitation
     try {
         return $this->toString();
     } catch (\Exception $e) {
         ErrorHandler::convertExceptionToError($e);
         return '';
     }
 }
All Usage Examples Of yii\base\ErrorHandler::convertExceptionToError