Reporting handled errors

Report handled PHP errors and exceptions to BugSnag.

Basic usage

In order to send handled exceptions to BugSnag, you can pass any Exception object to the notifyException method:

try {
    // Some potentially crashy code
} catch (Exception $exception) {
    $this->get('bugsnag')->notifyException($exception);
}

To send custom PHP errors to BugSnag, you can instead use notifyError:

$this->get('bugsnag')->notifyError('ErrorType', 'Something bad happened');

Adding callbacks

You can send custom diagnostic data with handled exceptions by passing a function to modify the error report:

try {
    // Some potentially crashy code
} catch (Exception $exception) {
    $this->get('bugsnag')->notifyException($exception, function ($report) {
        $report->setSeverity('info');
        $report->setMetaData([
            'account' => array(
                'paying' => true,
                'name' => 'Acme Co'
            )
        ]);
    });
}

Or when using notifyError:

$this->get('bugsnag')->notifyError('ErrorType', 'Something bad happened', function ($report) {
    $report->setSeverity('info');
    $report->setMetaData([
        'account' => array(
            'paying' => true,
            'name' => 'Acme Co'
        )
    ]);
});

For the full list of report customizations available, see the $report object documentation.