Error Tracking

The mParticle SDK lets you track “errors” and “exceptions”. These two terms have slightly different meanings:

  • An error is a designed error state in your app, such as a failed login.
  • An exception is an error thrown by the app or site.

As with other events, extra attributes can be passed via the Event Info object.

Log Errors

Map<String, String> errorInfo = new HashMap<String, String>();
errorInfo.put("reason", "Invalid username");

MParticle.getInstance().logError("Login failed", errorInfo);
HashMap<String, String>().apply {
    put("reason", "Invalid username")
}.also {
    MParticle.getInstance().logError("Login failed", it)

Log Exceptions

Exceptions are signaling mechanisms used by languages and APIs to indicate that an unexpected or impossible action was attempted. If the code that causes an exception is wrapped within a try/catch block, the app will be able to recover, and you can log that exception using the mParticle SDK.

Any available state information, as well as a stack trace at the moment of the exception, is automatically sent to mParticle when you log an exception.

try {
} catch (NullPointerException npe) {
try {
} catch (npe: NullPointerException) {

Automatic Exception Tracking

The mParticle SDK can also listen for unhandled exceptions. Note that only one listener can be created, so don’t do this if you already have other apps, such as HockeyApp or Fabric, listing for unhandled exceptions.

Enable this feature in the Android SDK:



While debugging a scenario that may lead, or is currently leading to, crashes and/or exceptions, it is often helpful to leave “breadcrumbs” along the way to better understand the context leading to the problem. A breadcrumb is a string explaining what your app code is about to attempt, or what it has just completed, for example “parsing began” or “parsing finished”.

The mParticle SDK lets you leave breadcrumbs with the leaveBreadcrumb method. You can also include additional custom attributes.

//fictional method that parses some object
private void parseResource(Resource someResource) {
    MParticle mp = MParticle.getInstance();

    try {
        mp.leaveBreadcrumb("parsing began");

        mp.leaveBreadcrumb("parsing title");

        mp.leaveBreadcrumb("parsing body");

        mp.leaveBreadcrumb("parsing footer");

        mp.leaveBreadcrumb("parsing finished!");
    } catch (Exception ex) {
//fictional method that parses some object
private fun parseResource(someResource: Resource) {
    MParticle.getInstance().apply {
        try {
            leaveBreadcrumb("parsing began")

            leaveBreadcrumb("parsing title")

            leaveBreadcrumb("parsing body")

            leaveBreadcrumb("parsing footer")

            leaveBreadcrumb("parsing finished!")
        } catch (ex: Exception) {

Was this page helpful?