How to access exception thrown in failed Laravel queued Job

laravel, php

Solution

This should work

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...
}

I'm assuming you made the `failed` method? If that's a thing in Laravel, this is the first I've seen of it.

Problem

I'm using a Laravel 5.2 `Job` and queuing it. When it fails it fires the `failed()` method on the job: ``` 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? ... } } ``` In the `failed()` method, how do I access the exception that was thrown when the `Job` failed? I understand I can catch the Exception in `handle()` but I wanted to know if it's accessable in `failed()`

Original source