Skip to content

Commit

Permalink
Update: 更新文档
Browse files Browse the repository at this point in the history
  • Loading branch information
NHZEX committed Nov 16, 2023
1 parent 01abe43 commit ee1ec17
Show file tree
Hide file tree
Showing 2 changed files with 37 additions and 2 deletions.
2 changes: 1 addition & 1 deletion doc/SUMMARY.md
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@
* [事件监听](components/event/index.md)
* [事件列表](core/events.md)
* [中间件](core/middleware.md)
* [全局错误处理](core/handleError.md)
* [全局异常处理](core/handleError.md)
* [内部进程间通讯](core/processCommunication.md)
* [Server 对象](core/server.md)
* [长连接分布式解决方案](core/long-connection-distributed.md)
Expand Down
37 changes: 36 additions & 1 deletion doc/core/handleError.md
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
# 错误处理
# 全局异常处理

[toc]

Expand Down Expand Up @@ -39,3 +39,38 @@ imi 框架底层支持将错误转为异常(通过`catchLevel`选项控制)
多个异常处理器将按顺序执行,可调用方法`stopPropagation`取消后续异常处理器执行并阻止系统默认的异常处理。

> 请务必确保异常处理器内不要再次抛出异常,做好异常捕获安全处理。
### Demo

```php
<?php

declare(strict_types=1);

namespace Imi\App;

use Imi\Log\AbstractErrorEventHandler;
use Imi\Log\Log;
use Psr\Log\LogLevel;

class ErrorEventHandler extends AbstractErrorEventHandler
{
public function handleError(int $errNo, string $errStr, string $errFile, int $errLine): void
{
if (str_contains($errFile, '/phpunit/src/'))
{
// 发现与用户代码无关错误,不影响程序执行,阻止其变为异常
$this->stopPropagation();

Log::log(LogLevel::INFO, $errStr);
}
}

public function handleException(\Throwable $throwable): void
{
// 可以处理更多异常状况...
}
}

```

0 comments on commit ee1ec17

Please sign in to comment.