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) {
    Bugsnag::notifyException($exception);
}

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

Bugsnag::notifyError('ErrorType', 'Something bad happened');

With diagnostic data

You can also send custom diagnostic data with handled exceptions:

try {
    // Some potentially crashy code
} catch (Exception $exception) {
    Bugsnag::notifyException($exception, [
      'account' => [
          'paying' => true,
          'name' => 'Acme Co'
      ]
    ]);
}

Or when using notifyError:

Bugsnag::notifyError('ErrorType', 'Something bad happened', [
    'account' => [
        'paying' => true,
        'name' => 'Acme Co'
    ]
]);

With a severity

You can set the severity of an error in BugSnag by including the severity option when reporting handled exceptions:

try {
    // Some potentially crashy code
} catch (Exception $exception) {
    Bugsnag::notifyException($exception, null, 'info');
}

Or when using notifyError:

Bugsnag::notifyError('ErrorType', 'Something bad happened', null, 'info');

Valid severities are error, warning and info.

Severity is displayed in the dashboard and can be used to filter the error list. By default all unhandled exceptions are set to error and all handled errors default to warning.

With diagnostic data and severity

You can send handled exceptions with both custom diagnostic data and severity as follows:

try {
    // Some potentially crashy code
} catch (Exception $exception) {
    Bugsnag::notifyException($exception, [
      'account' => [
          'paying' => true,
          'name' => 'Acme Co'
      ]
    ], 'info');
}

Or when using notifyError as follows:

Bugsnag::notifyError('ErrorType', 'Something bad happened', [
    'account' => [
        'paying' => true,
        'name' => 'Acme Co'
    ]
], 'info');