Reporting handled exceptions

Report handled exceptions to Bugsnag.

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 (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 (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 (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.