ErrorHandler
API reference › yii › console › ErrorHandler
ErrorHandler handles uncaught PHP errors and exceptions.
ErrorHandler is configured as an application component in Application by default.
You can access that instance via Yii::$app->errorHandler.
Properties
Section titled “Properties”| Property | Type | Description | Defined by |
|---|---|---|---|
$behaviors read-only | array<yii\<static>> | List of behaviors attached to this component. | yii\ |
$discardExistingOutput | bool | Whether to discard any existing page output before error display. Default: true. | yii\ |
$exception | Throwable| | The exception that is being handled currently. Default: null. | yii\ |
$memoryReserveSize | int | The size of the reserved memory. Default: 262144. | yii\ |
$silentExitOnException | bool | If true - handleException() will finish script with ExitCode::OK. false - ExitCode::UNSPECIFIED_ERROR. Default: null. Available since 2.0.36. | yii\ |
Methods
Section titled “Methods”| Method | Description | Defined by |
|---|---|---|
__construct() | Constructor. | yii\ |
__call() | Calls the named method which is not a class method. | yii\ |
__clone() | This method is called after the object is created by cloning an existing one. | yii\ |
__get() | Returns the value of a component property. | yii\ |
__isset() | Checks if a property is set, i.e. defined and not null. | yii\ |
__set() | Sets the value of a component property. | yii\ |
__unset() | Sets a component property to be null. | yii\ |
attachBehavior() | Attaches a behavior to this component. | yii\ |
attachBehaviors() | Attaches a list of behaviors to the component. | yii\ |
behaviors() | Returns a list of behaviors that this component should behave as. | yii\ |
canGetProperty() | Returns a value indicating whether a property can be read. | yii\ |
canSetProperty() | Returns a value indicating whether a property can be set. | yii\ |
className() static | Returns the fully qualified name of this class. | yii\ |
clearOutput() | Removes all output echoed before calling this method. | yii\ |
convertExceptionToString() static | Converts an exception into a simple string. | yii\ |
convertExceptionToVerboseString() static | Converts an exception into a string that has verbose information about the exception and its trace. | yii\ |
detachBehavior() | Detaches a behavior from the component. | yii\ |
detachBehaviors() | Detaches all behaviors from the component. | yii\ |
ensureBehaviors() | Makes sure that the behaviors declared in behaviors() are attached to this component. | yii\ |
getBehavior() | Returns the named behavior object. | yii\ |
getBehaviors() | Returns all behaviors attached to this component. | yii\ |
handleError() | Handles PHP execution errors such as warnings and notices. | yii\ |
handleException() | Handles uncaught PHP exceptions. | yii\ |
handleFatalError() | Handles fatal PHP errors. | yii\ |
hasEventHandlers() | Returns a value indicating whether there is any handler attached to the named event. | yii\ |
hasMethod() | Returns a value indicating whether a method is defined. | yii\ |
hasProperty() | Returns a value indicating whether a property is defined for this component. | yii\ |
init() | yii\ | |
logException() | Logs the given exception. | yii\ |
off() | Detaches an existing event handler from this component. | yii\ |
on() | Attaches an event handler to an event. | yii\ |
register() | Register this error handler. | yii\ |
trigger() | Triggers an event. | yii\ |
unregister() | Unregisters this error handler by restoring the PHP error and exception handlers. | yii\ |
formatMessage() protected | Colorizes a message for console output. | ErrorHandler |
handleFallbackExceptionMessage() protected | Handles exception thrown during exception processing in handleException(). | yii\ |
renderException() protected | Renders an exception using ansi format for console output. | ErrorHandler |
Events
Section titled “Events”| Event | Type | Description | Defined by |
|---|---|---|---|
EVENT_SHUTDOWN | yii\ | An event that is triggered when the handler is called by shutdown function via handleFatalError(). Event name: 'shutdown'. Available since 2.0.46. | yii\ |
Method details
Section titled “Method details”formatMessage()
Section titled “formatMessage() ”protected function formatMessage(string $message, array $format = [\yii\helpers\Console::FG_RED, \yii\helpers\Console::BOLD]): stringColorizes a message for console output.
Parameters
| Parameter | Type | Description |
|---|---|---|
$message | string | The message to colorize. |
$format | array | The message format. |
Returns
string: The colorized message.
See also
Console::ansiFormat()(for details on how to specify the message format.)
renderException()
Section titled “renderException() ”protected function renderException(Throwable $exception): mixedRenders an exception using ansi format for console output.