Updates to ErrorHandler, add missing type hint \Throwable (#18302)

* Updated phpdoc so it has \Throwable

- `abstract protected function renderException($exception);` is extended in web/ErrorHandler to also have `\Error`.
- `public static function convertExceptionToError($exception)` is called from widgets/ActiveField.php with 
```
/**
     * 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->render();
        } catch (\Exception $e) {
            ErrorHandler::convertExceptionToError($e);
            return '';
        } catch (\Throwable $e) {
            ErrorHandler::convertExceptionToError($e);
            return '';
        }
    }
```

* Add \Throwable to phpdoc in response.php 

The ErrorHandler has been updated in phpdoc to have throwable, this complets that change.

* Update ErrorHandler.php

fixed missing `|`
This commit is contained in:
My6UoT9
2020-09-30 01:34:23 +02:00
committed by GitHub
parent 1d7baabab5
commit 03da5bb689
2 changed files with 5 additions and 5 deletions

View File

@ -298,7 +298,7 @@ abstract class ErrorHandler extends Component
/**
* Renders the exception.
* @param \Exception $exception the exception to be rendered.
* @param \Exception|\Error|\Throwable $exception the exception to be rendered.
*/
abstract protected function renderException($exception);
@ -336,7 +336,7 @@ abstract class ErrorHandler extends Component
*
* This method can be used to convert exceptions inside of methods like `__toString()`
* to PHP errors because exceptions cannot be thrown inside of them.
* @param \Exception $exception the exception to convert to a PHP error.
* @param \Exception|\Throwable $exception the exception to convert to a PHP error.
*/
public static function convertExceptionToError($exception)
{
@ -345,7 +345,7 @@ abstract class ErrorHandler extends Component
/**
* Converts an exception into a simple string.
* @param \Exception|\Error $exception the exception being converted
* @param \Exception|\Error|\Throwable $exception the exception being converted
* @return string the string representation of the exception.
*/
public static function convertExceptionToString($exception)
@ -363,7 +363,7 @@ abstract class ErrorHandler extends Component
/**
* Converts an exception into a string that has verbose information about the exception and its trace.
* @param \Exception|\Error $exception the exception being converted
* @param \Exception|\Error|\Throwable $exception the exception being converted
* @return string the string representation of the exception.
*
* @since 2.0.14

View File

@ -295,7 +295,7 @@ class Response extends \yii\base\Response
/**
* Sets the response status code based on the exception.
* @param \Exception|\Error $e the exception object.
* @param \Exception|\Error|\Throwable $e the exception object.
* @throws InvalidArgumentException if the status code is invalid.
* @return $this the response object itself
* @since 2.0.12