ErrorHandler
API reference › PSR bridge › http › ErrorHandler
Handles exceptions with Yii error rendering and PSR-7 bridge support.
Properties
Section titled “Properties”| Property | Type | Description | Defined by |
|---|---|---|---|
$behaviors read-only | array<yii\<static>> | List of behaviors attached to this component. | yii\ |
$callStackItemView | string | The path of the view file for rendering exceptions and errors call stack element. Default: '@yii/views/errorHandler/callStackItem.php'. | yii\ |
$defaultResponseConfig | array<string, | Default configuration for creating fallback Response instances. Default: ['charset' => 'UTF-8']. | ErrorHandler |
$discardExistingOutput | bool | Whether to discard any existing page output before error display. Default: true. | yii\ |
$displayVars | array | List of the PHP predefined variables that should be displayed on the error page. Default: ['_GET',. Available since 2.0.7. | yii\ |
$errorAction | string| | The route (e.g. site/error) to the controller action that will be used to display external errors. Default: null. | yii\ |
$errorView | string | The path of the view file for rendering exceptions without call stack information. Default: '@yii/views/errorHandler/error.php'. | yii\ |
$exception | Throwable| | The exception that is being handled currently. Default: null. | yii\ |
$exceptionView | string | The path of the view file for rendering exceptions. Default: '@yii/views/errorHandler/exception.php'. | yii\ |
$maxSourceLines | int | Maximum number of source code lines to be displayed. Default: 19. | yii\ |
$maxTraceSourceLines | int | Maximum number of trace source code lines to be displayed. Default: 13. | yii\ |
$memoryReserveSize | int | Size of the memory reserve for handling fatal errors. Default: 1024 * 1024. | ErrorHandler |
$previousExceptionView | string | The path of the view file for rendering previous exceptions. Default: '@yii/views/errorHandler/previousException.php'. | yii\ |
$response write-only | Response | Response instance with desired configuration. | ErrorHandler |
$silentExitOnException | bool | If true - handleException() will finish script with ExitCode::OK. false - ExitCode::UNSPECIFIED_ERROR. Default: null. Available since 2.0.36. | yii\ |
$traceLine | string | Trace line with placeholders to be be substituted. Default: '{html}'. Available since 2.0.14. | 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\ |
addTypeLinks() | Adds informational links to the given PHP type/class. | yii\ |
argumentsToString() | Converts arguments array to its string representation. | 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() | Discards active output buffers, retaining level 1 when YII_ENV_TEST is true. | ErrorHandler |
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\ |
createFrameworkVersionLink() | Creates string containing HTML link which refers to the page with the current version of the framework and version number text. | yii\ |
createHttpStatusLink() | Creates HTML containing link to the page with the information on given HTTP status code. | yii\ |
createServerInformationLink() | Creates string containing HTML link which refers to the home page of determined web-server software and its full name. | 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\ |
getExceptionName() | Returns human-readable exception name. | yii\ |
handleError() | Handles PHP execution errors such as warnings and notices. | yii\ |
handleException() | Logs an exception and renders a bridge Yii response without sending it. | ErrorHandler |
handleFatalError() | Releases reserved memory before delegating fatal-error rendering to Yii. | ErrorHandler |
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\ |
htmlEncode() | Converts special characters to HTML entities. | yii\ |
init() | yii\ | |
isCoreFile() | Determines whether given name of the file belongs to the framework. | 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() | Registers PHP handlers with one weak shutdown dispatcher per process. | ErrorHandler |
releaseResponse() | Releases request references after emission and finalization. | ErrorHandler |
renderCallStack() | Renders call stack. | yii\ |
renderCallStackItem() | Renders a single call stack element. | yii\ |
renderFile() | Renders a view file as a PHP script. | yii\ |
renderPreviousExceptions() | Renders the previous exception stack for a given Exception. | yii\ |
renderRequest() | Renders the global variables of the request. | yii\ |
setResponse() | Sets the Response for error handling. | ErrorHandler |
trigger() | Triggers an event. | yii\ |
unregister() | Restores PHP handlers and releases the current registration’s reserve. | ErrorHandler |
convertExceptionToArray() protected | Converts an exception into an array. | yii\ |
getTypeUrl() protected | Returns the informational link URL for a given PHP type/class. | yii\ |
handleFallbackExceptionMessage() protected | Handles fallback exception rendering when an error occurs during exception processing. | ErrorHandler |
renderException() protected | Renders the exception and produces a Response object with appropriate error content. | ErrorHandler |
shouldRenderSimpleHtml() protected | yii\ | |
triggerAfterRender() protected | Triggers EVENT_AFTER_RENDER and returns final HTML content. | yii\ |
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\ |
Constants
Section titled “Constants”| Constant | Value | Description | Defined by |
|---|---|---|---|
EVENT_AFTER_RENDER | 'afterRender' | ErrorHandlerRenderEvent an event that is triggered after HTML error content is rendered. Available since 22.0. | yii\ |
Method details
Section titled “Method details”clearOutput()
Section titled “clearOutput() ”public function clearOutput(): voidDiscards active output buffers, retaining level 1 when YII_ENV_TEST is true.
handleException()
Section titled “handleException() ”public function handleException(Throwable $exception): yii2\extensions\psrbridge\http\ResponseLogs an exception and renders a bridge Yii response without sending it.
Unregisters the current error handler while rendering. If logging or rendering fails, returns a fallback response. PSR conversion remains the caller’s responsibility.
handleFatalError()
Section titled “handleFatalError() ”public function handleFatalError(): mixedReleases reserved memory before delegating fatal-error rendering to Yii.
Returns
mixed
register()
Section titled “register() ”public function register(): mixedRegisters PHP handlers with one weak shutdown dispatcher per process.
Returns
mixed
releaseResponse()
Section titled “releaseResponse() ”public function releaseResponse(): voidReleases request references after emission and finalization.
setResponse()
Section titled “setResponse() ”public function setResponse(yii2\extensions\psrbridge\http\Response $response): voidSets the Response for error handling.
The provided Response will be used for error responses, preserving configuration such as format, charset, and formatters. The Response will be cleared of any existing data before use.
Parameters
| Parameter | Type | Description |
|---|---|---|
$response | Response | Response instance with desired configuration. |
unregister()
Section titled “unregister() ”public function unregister(): mixedRestores PHP handlers and releases the current registration’s reserve.
Returns
mixed
handleFallbackExceptionMessage()
Section titled “handleFallbackExceptionMessage() ”protected function handleFallbackExceptionMessage(Throwable $exception, Throwable $previousException): yii2\extensions\psrbridge\http\ResponseHandles fallback exception rendering when an error occurs during exception processing.
Produces a Response object with a generic error message and, in debug mode, includes detailed exception
information and a sanitized snapshot of server variables, excluding sensitive keys.
renderException()
Section titled “renderException() ”protected function renderException(Throwable $exception): yii2\extensions\psrbridge\http\ResponseRenders the exception and produces a Response object with appropriate error content.
Handles exception rendering for HTML, raw, and array formats, supporting custom error views and error actions.
Parameters
| Parameter | Type | Description |
|---|---|---|
$exception | Throwable | Exception to render and convert to a Response object. |
Returns
Response: Object containing the rendered exception output.
Throws
yii\base\Exception: if an error occurs during error action execution.yii\base\InvalidRouteException: if the error action route is invalid or cannot be resolved.