Change how we report exceptions to the debugger.

This is only a refactoring/cleanup. Bug fixes with respect
to catch location, and more cleanups will follow.

Change-Id: I30d3c6260b0c8f8115a811621397225b88f2063a
diff --git a/runtime/interpreter/interpreter_common.cc b/runtime/interpreter/interpreter_common.cc
index 3ab7f30..754602f 100644
--- a/runtime/interpreter/interpreter_common.cc
+++ b/runtime/interpreter/interpreter_common.cc
@@ -491,12 +491,12 @@
   ThrowLocation throw_location;
   StackHandleScope<3> hs(self);
   Handle<mirror::Throwable> exception(hs.NewHandle(self->GetException(&throw_location)));
-  if (!self->IsExceptionReportedToInstrumentation() && instrumentation->HasExceptionCaughtListeners()) {
+  if (instrumentation->HasExceptionCaughtListeners()
+      && self->IsExceptionThrownByCurrentMethod(exception.Get())) {
     CatchLocationFinder clf(self, &exception);
     clf.WalkStack(false);
     instrumentation->ExceptionCaughtEvent(self, throw_location, clf.GetCatchMethod(),
                                           clf.GetCatchDexPc(), exception.Get());
-    self->SetExceptionReportedToInstrumentation(true);
   }
   bool clear_exception = false;
   uint32_t found_dex_pc;
@@ -507,13 +507,12 @@
                                                      &clear_exception);
   }
   if (found_dex_pc == DexFile::kDexNoIndex) {
+    // Exception is not caught by the current method. We will unwind to the
+    // caller. Notify any instrumentation listener.
     instrumentation->MethodUnwindEvent(self, shadow_frame.GetThisObject(),
                                        shadow_frame.GetMethod(), dex_pc);
   } else {
-    if (self->IsExceptionReportedToInstrumentation()) {
-      instrumentation->MethodUnwindEvent(self, shadow_frame.GetThisObject(),
-                                         shadow_frame.GetMethod(), dex_pc);
-    }
+    // Exception is caught in the current method. We will jump to the found_dex_pc.
     if (clear_exception) {
       self->ClearException();
     }