我正在使用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()
中访问
2 回答
这应该工作
我假设你做了
failed
方法?如果那是's a thing in Laravel, this is the first I'已经看到了它 .你可以使用这段代码:
但它可以从laravel 5.3获得 . 版 . 对于较旧的laravel版本,您可以使用一些不优雅的解决方案,如@Capitan Hypertext建议 .