Reporting handled errors

In order to quickly understand and fix errors, it is often helpful to send errors that have been handled by your application to BugSnag, with additional diagnostic data that is specific to the error.

Basic usage

If you would like to send handled errors to BugSnag, pass an error class and message to the notify function.

try {
  // Some potentially crashy code
} catch(e, stack) {
  bugsnag.notify(e, stack);

You can await bugsnag.notify which will resolve once the report has been persisted for delivery.

Customizing diagnostic data

You can send handled errors with diagnostic data or other customizations by passing a BugsnagOnErrorCallback (FutureOr<bool> Function(BugsnagEvent)) as an argument to notify.

The callback receives an BugsnagEvent object as a parameter which can be used to add or amend the data sent to your BugSnag dashboard. You can also return false from the callback to prevent the event being sent at all:

bugsnag.notify(e, stack, callback: (event) {
  // Add information
  event.addMetadata('account', const { 'name': 'Acme Co.' });
  event.addMetadata('account', const { 'paying_customer': true });

  // Increase severity
  event.severity = BugsnagSeverity.error;

  // Return `false` if you'd like to stop this error being reported extra
  return true;

See Customizing error reports for more information about the properties and methods available in an BugsnagEvent object.