您好,欢迎访问一九零五行业门户网

swoole错误处理的方法

在协程编程中可直接使用try/catch处理异常。但必须在协程内捕获,不得跨协程捕获异常。
不仅是应用层throw的exception,底层的一些错误也是可以被捕获的,如function、class、method不存在
错误
下面的代码中,try/catch和throw在不同的协程中,协程内无法捕获到此异常。当协程退出时,发现有未捕获的异常,将引起致命错误。
fatal error: uncaught runtimeexception
try { swoole\coroutine::create(function () { throw new \runtimeexception(__file__, __line__); });}catch (\throwable $e) { echo $e;}
正确
在协程内捕获异常。
function test() { throw new \runtimeexception(__file__, __line__);}swoole\coroutine::create(function () { try { test(); } catch (\throwable $e) { echo $e; }});
推荐学习: swoole视频教程
以上就是swoole错误处理的方法的详细内容。
其它类似信息

推荐信息