Abstract Class yii\base\ErrorHandler
ErrorHandler 处理未捕获的 PHP 错误和异常。
默认情况下,ErrorHandler 在 yii\base\Application 中配置为应用程序组件。
您可以通过 Yii::$app->errorHandler
访问该实例。
有关 ErrorHandler 的更多详细信息和用法信息,请参阅 有关错误处理的指南文章。
公共属性
属性 | 类型 | 描述 | 被定义在 |
---|---|---|---|
$behaviors | yii\base\Behavior[] | List of behaviors attached to this component | yii\base\Component |
$discardExistingOutput | boolean | 是否在错误显示之前丢弃任何现有页面输出。默认为 true。 | yii\base\ErrorHandler |
$exception | Exception|null | 当前正在处理的异常。 | yii\base\ErrorHandler |
$memoryReserveSize | integer | The size of the reserved memory. | yii\base\ErrorHandler |
公共方法
方法 | 描述 | 被定义在 |
---|---|---|
__call() | Calls the named method which is not a class method. | yii\base\Component |
__clone() | This method is called after the object is created by cloning an existing one. | yii\base\Component |
__construct() | Constructor. | yii\base\BaseObject |
__get() | Returns the value of a component property. | yii\base\Component |
__isset() | Checks if a property is set, i.e. defined and not null. | yii\base\Component |
__set() | Sets the value of a component property. | yii\base\Component |
__unset() | Sets a component property to be null. | yii\base\Component |
attachBehavior() | Attaches a behavior to this component. | yii\base\Component |
attachBehaviors() | Attaches a list of behaviors to the component. | yii\base\Component |
behaviors() | Returns a list of behaviors that this component should behave as. | yii\base\Component |
canGetProperty() | Returns a value indicating whether a property can be read. | yii\base\Component |
canSetProperty() | Returns a value indicating whether a property can be set. | yii\base\Component |
className() | Returns the fully qualified name of this class. | yii\base\BaseObject |
clearOutput() | 在调用此方法之前删除所有回显的输出。 | yii\base\ErrorHandler |
convertExceptionToError() | 将异常转换为 PHP 错误。 | yii\base\ErrorHandler |
convertExceptionToString() | 将异常转换为简单字符串。 | yii\base\ErrorHandler |
convertExceptionToVerboseString() | 将异常转换为具有关于异常及其跟踪的详细信息的字符串。 | yii\base\ErrorHandler |
detachBehavior() | Detaches a behavior from the component. | yii\base\Component |
detachBehaviors() | Detaches all behaviors from the component. | yii\base\Component |
ensureBehaviors() | Makes sure that the behaviors declared in behaviors() are attached to this component. | yii\base\Component |
getBehavior() | Returns the named behavior object. | yii\base\Component |
getBehaviors() | Returns all behaviors attached to this component. | yii\base\Component |
handleError() | Handles PHP execution errors such as warnings and notices. | yii\base\ErrorHandler |
handleException() | 处理未捕获的 PHP 异常。 | yii\base\ErrorHandler |
handleFatalError() | Handles fatal PHP errors. | yii\base\ErrorHandler |
handleHhvmError() | Handles HHVM execution errors such as warnings and notices. | yii\base\ErrorHandler |
hasEventHandlers() | Returns a value indicating whether there is any handler attached to the named event. | yii\base\Component |
hasMethod() | Returns a value indicating whether a method is defined. | yii\base\Component |
hasProperty() | Returns a value indicating whether a property is defined for this component. | yii\base\Component |
init() | Initializes the object. | yii\base\BaseObject |
logException() | Logs the given exception. | yii\base\ErrorHandler |
off() | Detaches an existing event handler from this component. | yii\base\Component |
on() | Attaches an event handler to an event. | yii\base\Component |
register() | 注册此错误处理程序。 | yii\base\ErrorHandler |
trigger() | Triggers an event. | yii\base\Component |
unregister() | 通过还原 PHP 错误和异常处理程序取消注册此错误处理程序。 | yii\base\ErrorHandler |
受保护的方法
方法 | 描述 | 被定义在 |
---|---|---|
handleFallbackExceptionMessage() | Handles exception thrown during exception processing in handleException(). | yii\base\ErrorHandler |
renderException() | Renders the exception. | yii\base\ErrorHandler |
属性详情
是否在错误显示之前丢弃任何现有页面输出。默认为 true。
当前正在处理的异常。
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 void clearOutput() |
将异常转换为 PHP 错误。
此方法可用于将类似 __toString()
的方法内的异常转换为 PHP 错误,因为异常不能在其中抛出。
public static void convertExceptionToError($exception) | ||
$exception | Exception | 转换为 PHP 错误的异常。 |
将异常转换为简单字符串。
public static string convertExceptionToString($exception) | ||
$exception | Exception|Error | 被转换的异常 |
return | string | 异常的字符串表示形式。 |
---|
将异常转换为具有关于异常及其跟踪的详细信息的字符串。
public static string convertExceptionToVerboseString($exception) | ||
$exception | Exception|Error | 被转换的异常 |
return | string | 异常的字符串表示形式。 |
---|
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.
public boolean handleError($code, $message, $file, $line) | ||
$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. |
---|---|---|
throws | yii\base\ErrorException |
处理未捕获的 PHP 异常。
此方法实现为 PHP 异常处理程序。
public void handleException($exception) | ||
$exception | Exception | 未捕获的异常 |
Handles exception thrown during exception processing in handleException().
protected void handleFallbackExceptionMessage($exception, $previousException) | ||
$exception | Exception|Throwable | Exception that was thrown during main exception processing. |
$previousException | Exception | Main exception processed in handleException(). |
Handles fatal PHP errors.
public void handleFatalError() |
Handles HHVM execution errors such as warnings and notices.
This method is used as a HHVM error handler. It will store exception that will be used in fatal error handler
public boolean handleHhvmError($code, $message, $file, $line, $context, $backtrace) | ||
$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. |
---|---|---|
throws | yii\base\ErrorException |
Logs the given exception.
public void logException($exception) | ||
$exception | Exception | The exception to be logged |
注册此错误处理程序。
public void register() |
Renders the exception.
protected abstract void renderException($exception) | ||
$exception | Exception | The exception to be rendered. |
通过还原 PHP 错误和异常处理程序取消注册此错误处理程序。
public void unregister() |