PHP Class yii\base\ErrorHandler

ErrorHandler is configured as an application component in Application by default. You can access that instance via Yii::$app->errorHandler. For more details and usage information on ErrorHandler, see the guide article on handling errors.
Since: 2.0
Author: Qiang Xue ([email protected])
Author: Alexander Makarov ([email protected])
Author: Carsten Brandt ([email protected])
Inheritance: extends Component
Show file Open project: yiisoft/yii2 Class Usage Examples

Public Properties

Property Type Description
$discardExistingOutput whether to discard any existing page output before error display. Defaults to true.
$exception the exception that is being handled currently.
$memoryReserveSize the size of the reserved memory. A portion of memory is pre-allocated so that when an out-of-memory issue occurs, the error handler is able to handle the error with the help of this reserved memory. If you set this value to be 0, no memory will be reserved. Defaults to 256KB.

Public Methods

Method Description
clearOutput ( ) Removes all output echoed before calling this method.
convertExceptionToError ( Exception $exception ) Converts an exception into a PHP error.
convertExceptionToString ( Exception $exception ) : string Converts an exception into a simple string.
handleError ( integer $code, string $message, string $file, integer $line ) : boolean Handles PHP execution errors such as warnings and notices.
handleException ( Exception $exception ) Handles uncaught PHP exceptions.
handleFatalError ( ) Handles fatal PHP errors
handleHhvmError ( integer $code, string $message, string $file, integer $line, mixed $context, mixed $backtrace ) : boolean Handles HHVM execution errors such as warnings and notices.
logException ( Exception $exception ) Logs the given exception
register ( ) Register this error handler
unregister ( ) Unregisters this error handler by restoring the PHP error and exception handlers.

Protected Methods

Method Description
handleFallbackExceptionMessage ( Exception | Throwable $exception, Exception $previousException ) Handles exception thrown during exception processing in ErrorHandler::handleException.
renderException ( Exception $exception ) Renders the exception.

Method Details

clearOutput() public method

Removes all output echoed before calling this method.
public clearOutput ( )

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.

convertExceptionToString() public static method

Converts an exception into a simple string.
public static convertExceptionToString ( Exception $exception ) : string
$exception Exception the exception being converted
return string the string representation of the exception.

handleError() public method

This method is used as a PHP error handler. It will simply raise an ErrorException.
public handleError ( integer $code, string $message, string $file, integer $line ) : boolean
$code integer the level of the error raised.
$message string the error message.
$file string the filename that the error was raised in.
$line integer the line number the error was raised at.
return boolean whether the normal error handler continues.

handleException() public method

This method is implemented as a PHP exception handler.
public handleException ( Exception $exception )
$exception Exception the exception that is not caught

handleFallbackExceptionMessage() protected method

Handles exception thrown during exception processing in ErrorHandler::handleException.
Since: 2.0.11
protected handleFallbackExceptionMessage ( Exception | Throwable $exception, Exception $previousException )
$exception Exception | Throwable Exception that was thrown during main exception processing.
$previousException Exception Main exception processed in [[handleException()]].

handleFatalError() public method

Handles fatal PHP errors
public handleFatalError ( )

handleHhvmError() public method

This method is used as a HHVM error handler. It will store exception that will be used in fatal error handler
Since: 2.0.6
public handleHhvmError ( integer $code, string $message, string $file, integer $line, mixed $context, mixed $backtrace ) : boolean
$code integer the level of the error raised.
$message string the error message.
$file string the filename that the error was raised in.
$line integer the line number the error was raised at.
$context mixed
$backtrace mixed trace of error
return boolean whether the normal error handler continues.

logException() public method

Logs the given exception
Since: 2.0.3 this method is now public.
public logException ( Exception $exception )
$exception Exception the exception to be logged

register() public method

Register this error handler
public register ( )

renderException() abstract protected method

Renders the exception.
abstract protected renderException ( Exception $exception )
$exception Exception the exception to be rendered.

unregister() public method

Unregisters this error handler by restoring the PHP error and exception handlers.
public unregister ( )

Property Details

$discardExistingOutput public property

whether to discard any existing page output before error display. Defaults to true.
public $discardExistingOutput

$exception public property

the exception that is being handled currently.
public $exception

$memoryReserveSize public property

the size of the reserved memory. A portion of memory is pre-allocated so that when an out-of-memory issue occurs, the error handler is able to handle the error with the help of this reserved memory. If you set this value to be 0, no memory will be reserved. Defaults to 256KB.
public $memoryReserveSize