gpt4 book ai didi

php - 如何访问失败的 Laravel 排队作业中抛出的异常

转载 作者:行者123 更新时间:2023-12-03 01:06:04 25 4
gpt4 key购买 nike

我正在使用 Laravel 5.2 Job 并将其排队。当失败时,它会触发作业的 failed() 方法:

class ConvertJob extends Job implements SelfHandling, ShouldQueue
{
use InteractsWithQueue, DispatchesJobs;


public function __construct()
{

}

public function handle()
{
// ... do stuff and fail ...
}

public function failed()
{
// ... what exception was thrown? ...
}
}

failed()方法中,如何访问Job失败时抛出的异常?

我知道我可以在handle()中捕获异常,但我想知道它是否可以在failed()中访问

最佳答案

这应该有效

public function handle()
{
// ... do stuff
$bird = new Bird();

try {
$bird->is('the word');
}
catch(Exception $e) {
// bird is clearly not the word
$this->failed($e);
}
}

public function failed($exception)
{
$exception->getMessage();
// etc...
}

我假设您执行了失败方法?如果 Laravel 中有这样的东西,这是我第一次看到它。

关于php - 如何访问失败的 Laravel 排队作业中抛出的异常,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/40084712/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com