package com.leanplum.monitoring;

import android.content.Context;

import com.leanplum.internal.Log;

public class ExceptionHandler {
  private static final String LEANPLUM_CRASH_REPORTER_CLASS =
          "com.leanplum.monitoring.internal.LeanplumExceptionReporter";
  private static final ExceptionHandler instance = new ExceptionHandler();
  public ExceptionReporting exceptionReporter = null;

  private ExceptionHandler() {}

  public static ExceptionHandler getInstance() {
    return instance;
  }

  public void setContext(Context context) {
    try {
      // Class.forName runs the static initializer in LeanplumExceptionReporter
      // which sets the exceptionReporter on the singleton
      Class.forName(LEANPLUM_CRASH_REPORTER_CLASS);
      if (exceptionReporter != null) {
        try {
          exceptionReporter.setContext(context);
        } catch (Throwable t) {
          Log.e("LeanplumCrashHandler", t);
        }
      }
    } catch (Throwable t) {
      Log.e("LeanplumCrashHandler", t);
    }
  }

  public void reportException(Throwable exception) {
    if (exceptionReporter != null) {
      try {
        exceptionReporter.reportException(exception);
      } catch (Throwable t) {
        Log.e("LeanplumCrashHandler", t);
      }
    }
  }
}

@@ -895,37 +895,41 @@
  Log.e(%22Leanplum
-Crash
+Exception
 Handler%22, t);%0A  
@@ -940,24 +940,239 @@
   %7D%0A      %7D%0A
+    %7D catch (ClassNotFoundException t) %7B%0A      Log.i(%22LeanplumExceptionHandler could not initialize Exception Reporting.%22 +%0A              %22This is expected if you have not included the leanplum-monitoring module%22);%0A
     %7D catch 
@@ -1200,37 +1200,41 @@
  Log.e(%22Leanplum
-Crash
+Exception
 Handler%22, t);%0A  
@@ -1455,13 +1455,17 @@
 plum
-Crash
+Exception
 Hand

Change log level to Info if leanplum-monitoring not included (#209)