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.

This documentation is for version 6 of the Bugsnag Unity notifier. If you are using older versions, we recommend upgrading to the latest release using our Upgrade guide. Documentation for the previous release can be found on our legacy pages.

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 (Exception e)
{
    Bugsnag.Notify(e);
}

By default, the error class is used along with the site of the call to Notify to group similar occurrences together on our dashboard. If you’d like occurrences to be grouped together, use a static string for the name or class, and put information that may change in the message.

See Error grouping for more information about about how and why events are grouped into errors.

Customizing diagnostic data

You can send handled errors with diagnostic data or other customizations by passing a callback as an argument to Notify.

The callback receives an Event 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:

try
{
    // Some potentially crashy code
}
catch (Exception e)
{
    Bugsnag.Notify(e, @event => {

        // Add extra information
        @event.AddMetadata("account", "name", "Acme Co.");
        @event.AddMetadata("account", "paying_customer", true);

        // Increase severity
        @event.Severity = Severity.Error;

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

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