Report handled PHP errors and exceptions to BugSnag.
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');
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'
]
]);
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
.
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');