自定义进程,支持异常回调,可以用于业务逻辑发生错误时的上报记录工作。
只需要实现public function onException(\Throwable $throwable)
接口方法,我们通过代码来举例:
<?php
namespace box\process;
use design\AbstractProcess;
class Demo extends AbstractProcess
{
// 进程逻辑接口方法
public function run() {
// 调用一个不存在的方法
test();
}
// 业务进程发生异常时回调
public function onException(\Throwable $throwable)
{
// $throwable->getMessage(); 错误内容
// $throwable->getFile(); 错误文件
// $throwable->getLine(); 错误行数
}
}
底层是使用的try {} catch {}
转发实现。