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

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

$bugsnagWordpress->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) {
    $bugsnagWordpress->notifyException($exception, [
      'account' => [
          'paying' => true,
          'name' => 'Acme Co'
      ]
    ]);
}

Or when using notifyError:

$bugsnagWordpress->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) {
    $bugsnagWordpress->notifyException($exception, null, 'info');
}

Or when using notifyError:

$bugsnagWordpress->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) {
    $bugsnagWordpress->notifyException($exception, [
      'account' => [
          'paying' => true,
          'name' => 'Acme Co'
      ]
    ], 'info');
}

Or when using notifyError as follows:

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