Skip to content

ErrorHandler ​

Type
Class
Namespace
craft\web
Inherits
craft\web\ErrorHandler » yii\web\ErrorHandler » yii\base\ErrorHandler » yii\base\Component » yii\base\BaseObject
Implements
yii\base\Configurable
Since
3.0.0

Class ErrorHandler

View source

Public Properties ​

PropertyDescription
behaviorsyii\base\Behavior – List of behaviors attached to this component.
callStackItemViewstring – The path of the view file for rendering exceptions and errors call stack element.
discardExistingOutputboolean – Whether to discard any existing page output before error display.
displayVarsarray – List of the PHP predefined variables that should be displayed on the error page.
errorActionstring, null – The route (e.g. site/error) to the controller action that will be used to display external errors.
errorViewstring – The path of the view file for rendering exceptions without call stack information.
exceptionThrowable, null – The exception that is being handled currently.
exceptionViewstring – The path of the view file for rendering exceptions.
maxSourceLinesinteger – Maximum number of source code lines to be displayed.
maxTraceSourceLinesinteger – Maximum number of trace source code lines to be displayed.
memoryReserveSizeinteger – The size of the reserved memory.
previousExceptionViewstring – The path of the view file for rendering previous exceptions.
silentExitOnExceptionboolean – If true - handleException() will finish script with ExitCode::OK.
traceLinestring – Trace line with placeholders to be be substituted.

Public Methods ​

MethodDescription
__call()Calls the named method which is not a class method.
__clone()This method is called after the object is created by cloning an existing one.
__construct()Constructor.
__get()Returns the value of a component property.
__isset()Checks if a property is set, i.e. defined and not null.
__set()Sets the value of a component property.
__unset()Sets a component property to be null.
addTypeLinks()Adds informational links to the given PHP type/class.
argumentsToString()Converts arguments array to its string representation.
attachBehavior()Attaches a behavior to this component.
attachBehaviors()Attaches a list of behaviors to the component.
behaviors()Returns a list of behaviors that this component should behave as.
canGetProperty()Returns a value indicating whether a property can be read.
canSetProperty()Returns a value indicating whether a property can be set.
className()Returns the fully qualified name of this class.
clearOutput()Removes all output echoed before calling this method.
convertExceptionToError()Converts an exception into a PHP error.
convertExceptionToString()Converts an exception into a simple string.
convertExceptionToVerboseString()Converts an exception into a string that has verbose information about the exception and its trace.
createFrameworkVersionLink()Creates string containing HTML link which refers to the page with the current version of the framework and version number text.
createHttpStatusLink()Creates HTML containing link to the page with the information on given HTTP status code.
createServerInformationLink()Creates string containing HTML link which refers to the home page of determined web-server software and its full name.
detachBehavior()Detaches a behavior from the component.
detachBehaviors()Detaches all behaviors from the component.
ensureBehaviors()Makes sure that the behaviors declared in behaviors() are attached to this component.
exceptionAsArray()Returns an array representation of the given throwable.
getBehavior()Returns the named behavior object.
getBehaviors()Returns all behaviors attached to this component.
getExceptionName()Returns human-readable exception name.
handleError()Handles PHP execution errors such as warnings and notices.
handleException()Handles uncaught PHP exceptions.
handleFatalError()Handles fatal PHP errors.
handleHhvmError()Handles HHVM execution errors such as warnings and notices.
hasEventHandlers()Returns a value indicating whether there is any handler attached to the named event.
hasMethod()Returns a value indicating whether a method is defined.
hasProperty()Returns a value indicating whether a property is defined for this component.
htmlEncode()Converts special characters to HTML entities.
init()
isCoreFile()Determines whether given name of the file belongs to the framework.
logException()Logs the given exception.
off()Detaches an existing event handler from this component.
on()Attaches an event handler to an event.
register()Register this error handler.
renderCallStack()Renders call stack.
renderCallStackItem()Renders a single call stack element.
renderFile()Renders a view file as a PHP script.
renderPreviousExceptions()Renders the previous exception stack for a given Exception.
renderRequest()Renders the global variables of the request.
showExceptionDetails()Returns whether full exception details should be shown for the current user.
trigger()Triggers an event.
unregister()Unregisters this error handler by restoring the PHP error and exception handlers.

exceptionAsArray() ​

Since
4.9.0

Returns an array representation of the given throwable.

View source

Arguments ​

Returns ​

array

getExceptionName() ​

Returns human-readable exception name.

View source

Arguments ​

Returns ​

string, null – Human-readable exception name or null if it cannot be determined

handleError() ​

Handles PHP execution errors such as warnings and notices.

This method is used as a PHP error handler. It will simply raise an yii\base\ErrorException.

View source

Arguments ​

  • $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.

Returns ​

boolean – Whether the normal error handler continues.

Throws ​

handleException() ​

Handles uncaught PHP exceptions.

This method is implemented as a PHP exception handler.

View source

Arguments ​

  • $exception (Throwable) – The exception that is not caught

isCoreFile() ​

Determines whether given name of the file belongs to the framework.

View source

Arguments ​

  • $file (string) – Name to be checked.

Returns ​

boolean – Whether given name of the file belongs to the framework.

renderCallStackItem() ​

Renders a single call stack element.

View source

Arguments ​

  • $file (string, null) – Name where call has happened.
  • $line (integer, null) – Number on which call has happened.
  • $class (string, null) – Called class name.
  • $method (string, null) – Called function/method name.
  • $args (array) – Array of method arguments.
  • $index (integer) – Number of the call stack element.

Returns ​

string – HTML content of the rendered call stack element.

showExceptionDetails() ​

Since
4.9.0

Returns whether full exception details should be shown for the current user.

View source

Returns ​

boolean

Protected Methods ​

MethodDescription
convertExceptionToArray()Converts an exception into an array.
getTypeUrl()Returns the informational link URL for a given PHP type/class.
handleFallbackExceptionMessage()Handles exception thrown during exception processing in handleException().
renderException()Renders the exception.
shouldRenderSimpleHtml()

getTypeUrl() ​

Returns the informational link URL for a given PHP type/class.

View source

Arguments ​

  • $class (string) – The type or class name.
  • $method (string, null) – The method name.

Returns ​

string, null – The informational link URL.

renderException() ​

Renders the exception.

View source

Arguments ​

  • $exception (Throwable) – The exception to be rendered.

shouldRenderSimpleHtml() ​

Since
3.4.10

View source

Returns ​

boolean – If simple HTML should be rendered

Events ​

EVENT_BEFORE_HANDLE_EXCEPTION ​

Type
craft\events\ExceptionEvent

The event that is triggered before handling an exception.