Reporting handled exceptions

Report handled exceptions to BugSnag.

This documentation is for version 4 of the BugSnag Android notifier. We recommend upgrading to the latest release using our Upgrade guide. Documentation for the current release can be found here.

Basic usage

In order to send handled exceptions to BugSnag, you can pass any Throwable object to the notify method:

import com.bugsnag.android.Bugsnag;

try {
    // Some potentially crashy code
} catch (Throwable exception) {
    Bugsnag.notify(exception);
}
import com.bugsnag.android.Bugsnag

try {
    // Some potentially crashy code
} catch (e: Throwable) {
    Bugsnag.notify(e)
}

With a severity

You can set the severity of an error in BugSnag by including the severity option when notifying bugsnag of the error.

import com.bugsnag.android.Bugsnag;
import com.bugsnag.android.Severity;

try {
    // Some potentially crashy code
} catch (Throwable exception) {
    Bugsnag.notify(exception, Severity.INFO);
}
import com.bugsnag.android.Bugsnag
import com.bugsnag.android.Severity

try {
    // Some potentially crashy code
} catch (e: Throwable) {
    Bugsnag.notify(e, Severity.INFO)
}

Valid severities are Severity.ERROR, Severity.WARNING and Severity.INFO.

Severity is displayed in the dashboard and can be used to filter the error list. By default all crashes (or unhandled exceptions) are set to Bugsnag.ERROR and all Bugsnag.notify calls default to Bugsnag.WARNING.

With diagnostic data

You can send handled exceptions with diagnostic data or other customizations using a Callback. The callback receives a Report object as a parameter:

import com.bugsnag.android.Bugsnag;
import com.bugsnag.android.Severity;
import com.bugsnag.android.Callback;

try {
    // Some potentially crashy code
} catch (Throwable exception) {
    Bugsnag.notify(exception, new Callback() {
        @Override
        public void beforeNotify(Report report) {
            report.getError().getMetaData().addToTab("Account", "name", "Acme Co");
            report.getError().setContext("slider menu");
        }
    });
}
import com.bugsnag.android.Bugsnag
import com.bugsnag.android.Severity
import com.bugsnag.android.Callback

try {
    // Some potentially crashy code
} catch (e: Throwable) {
    Bugsnag.notify(exception, {
        val error = it.error!!
        error.metaData.addToTab("Account", "name", "Acme Co")
        error.context = "slider menu"
    })
}

The Report object includes the apiKey used and the error which will be sent to BugSnag. See the error object for all of the fields available to be edited within the callback.