title: Exception thrown inside a synchronized block java/android
body: <p>I'm experiencing something weird when it comes to synchronized blocks. I have a cache that needs to be inside a synchronized block. There is an exception happening inside the block and for some reason is not going to the catch block. I tried debugging it, and I saw that it calls InvocationTargetException constructor and then it goes to ThreadGroup uncaughtException(Thread t, Throwable e) method.</p>
  
  <p>I have a try catch surrounding the synchronized block, in fact there is another inner try-catch covering the line of code where the exception happens...</p>
  
  <p>Does anyone know why it's not getting it to the catch block?</p>
  
  <p>I even try to literally try to catch the InvocationTargetException as well as the Exception, and as expected, it doesn't compile because nothing inside is throwing that kind of exception. I do understand the reason of the exception though, my concern is that it was't caught and kill the thread.</p>
  
  <pre><code>@Override
  public void onLocationChanged(Location loc) 
  {
      if(lastKnownLatitude != null &amp;&amp; lastKnownLongitude != null)
      {
              try
              {
  
                  synchronized (dataManager.getRegisteredGeo()) {for(String geoName : dataManager.getRegisteredGeo().keySet())
                      {
                          GeoNotification geoNotification = dataManager.getRegisteredGeo().get(geoName);
                          boolean isInside = geoNotification.isLocationInsideFence(loc.getLatitude(), loc.getLongitude());
  
  
                          geoNotification.setLastKnownDeviceInside(isInside);
                          GeoUpdateMsg updateMsg = new GeoUpdateMsg(geoNotification.getTransactionId());
                          updateMsg.sendData(updateMsg.serializeObjectIntoXml());
  
                      }   
                  }
              }
              catch(Exception e)
              {
                  Logger.LogError("Exception while processing  geo notifications" + e.getMessage());
              }
      }
  }
  </code></pre>
  
  <p>This is the event that fires when the device location changed</p>
  
  <p>This is what I got from the log cat, the exception wasn't caught</p>
  
  <pre><code>04-22 13:12:35.762: E/AndroidRuntime(2121): FATAL EXCEPTION: main
  04-22 13:12:35.762: E/AndroidRuntime(2121): java.lang.NoClassDefFoundError: org/joda/convert/FromString
  04-22 13:12:35.762: E/AndroidRuntime(2121):     at java.lang.reflect.Method.getDeclaredAnnotations(Native Method)
  04-22 13:12:35.762: E/AndroidRuntime(2121):     at java.lang.reflect.Method.getDeclaredAnnotations(Method.java:267)
  04-22 13:12:35.762: E/AndroidRuntime(2121):     at org.simpleframework.xml.core.MethodDetail.&lt;init&gt;(MethodDetail.java:57)
  04-22 13:12:35.762: E/AndroidRuntime(2121):     at org.simpleframework.xml.core.DetailScanner.methods(DetailScanner.java:411)
  04-22 13:12:35.762: E/AndroidRuntime(2121):     at org.simpleframework.xml.core.DetailScanner.scan(DetailScanner.java:366)
  04-22 13:12:35.762: E/AndroidRuntime(2121):     at org.simpleframework.xml.core.DetailScanner.&lt;init&gt;(DetailScanner.java:140)
  04-22 13:12:35.762: E/AndroidRuntime(2121):     at org.simpleframework.xml.core.DetailExtractor.getDetail(DetailExtractor.java:107)
  04-22 13:12:35.762: E/AndroidRuntime(2121):     at org.simpleframework.xml.core.Support.getDetail(Support.java:278)
  04-22 13:12:35.762: E/AndroidRuntime(2121):     at org.simpleframework.xml.core.Support.getDetail(Support.java:271)
  04-22 13:12:35.762: E/AndroidRuntime(2121):     at org.simpleframework.xml.core.ScannerFactory.getInstance(ScannerFactory.java:76)
  04-22 13:12:35.762: E/AndroidRuntime(2121):     at org.simpleframework.xml.core.Support.getScanner(Support.java:357)
  04-22 13:12:35.762: E/AndroidRuntime(2121):     at org.simpleframework.xml.core.Source.getScanner(Source.java:271)
  04-22 13:12:35.762: E/AndroidRuntime(2121):     at org.simpleframework.xml.core.Source.getCaller(Source.java:300)
  04-22 13:12:35.762: E/AndroidRuntime(2121):     at org.simpleframework.xml.core.Composite.writeReplace(Composite.java:1147)
  04-22 13:12:35.762: E/AndroidRuntime(2121):     at org.simpleframework.xml.core.Composite.writeUnion(Composite.java:1124)
  04-22 13:12:35.762: E/AndroidRuntime(2121):     at org.simpleframework.xml.core.Composite.writeElements(Composite.java:1098)
  04-22 13:12:35.762: E/AndroidRuntime(2121):     at org.simpleframework.xml.core.Composite.writeSection(Composite.java:1004)
  04-22 13:12:35.762: E/AndroidRuntime(2121):     at org.simpleframework.xml.core.Composite.write(Composite.java:975)
  04-22 13:12:35.762: E/AndroidRuntime(2121):     at org.simpleframework.xml.core.Composite.write(Composite.java:952)
  04-22 13:12:35.762: E/AndroidRuntime(2121):     at org.simpleframework.xml.core.Traverser.write(Traverser.java:236)
  04-22 13:12:35.762: E/AndroidRuntime(2121):     at org.simpleframework.xml.core.Traverser.write(Traverser.java:208)
  04-22 13:12:35.762: E/AndroidRuntime(2121):     at org.simpleframework.xml.core.Traverser.write(Traverser.java:186)
  04-22 13:12:35.762: E/AndroidRuntime(2121):     at org.simpleframework.xml.core.Persister.write(Persister.java:1180)
  04-22 13:12:35.762: E/AndroidRuntime(2121):     at org.simpleframework.xml.core.Persister.write(Persister.java:1162)
  04-22 13:12:35.762: E/AndroidRuntime(2121):     at org.simpleframework.xml.core.Persister.write(Persister.java:1140)
  04-22 13:12:35.762: E/AndroidRuntime(2121):     at org.simpleframework.xml.core.Persister.write(Persister.java:1259)
  04-22 13:12:35.762: E/AndroidRuntime(2121):     at org.simpleframework.xml.core.Persister.write(Persister.java:1241)
  04-22 13:12:35.762: E/AndroidRuntime(2121):     at org.simpleframework.xml.core.Persister.write(Persister.java:1222)
  04-22 13:12:35.762: E/AndroidRuntime(2121):     at com.medusa.client.transactions.TransactionsGoingOut.serializeObjectIntoXml(TransactionsGoingOut.java:57)
  04-22 13:12:35.762: E/AndroidRuntime(2121):     at com.medusa.client.transactions.messages.GeoFenceUpdateMsg.serializeObjectIntoXml(GeoFenceUpdateMsg.java:64)
  04-22 13:12:35.762: E/AndroidRuntime(2121):     at com.medusa.client.smsIntercept.GPSTracker.onLocationChanged(GPSTracker.java:312)
  04-22 13:12:35.762: E/AndroidRuntime(2121):     at android.location.LocationManager$ListenerTransport._handleMessage(LocationManager.java:255)
  04-22 13:12:35.762: E/AndroidRuntime(2121):     at android.location.LocationManager$ListenerTransport.access$000(LocationManager.java:184)
  04-22 13:12:35.762: E/AndroidRuntime(2121):     at android.location.LocationManager$ListenerTransport$1.handleMessage(LocationManager.java:200)
  04-22 13:12:35.762: E/AndroidRuntime(2121):     at android.os.Handler.dispatchMessage(Handler.java:99)
  04-22 13:12:35.762: E/AndroidRuntime(2121):     at android.os.Looper.loop(Looper.java:137)
  04-22 13:12:35.762: E/AndroidRuntime(2121):     at android.app.ActivityThread.main(ActivityThread.java:5041)
  04-22 13:12:35.762: E/AndroidRuntime(2121):     at java.lang.reflect.Method.invokeNative(Native Method)
  04-22 13:12:35.762: E/AndroidRuntime(2121):     at java.lang.reflect.Method.invoke(Method.java:511)
  04-22 13:12:35.762: E/AndroidRuntime(2121):     at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:793)
  04-22 13:12:35.762: E/AndroidRuntime(2121):     at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:560)
  04-22 13:12:35.762: E/AndroidRuntime(2121):     at dalvik.system.NativeStart.main(Native Method)
  04-22 13:12:35.762: E/AndroidRuntime(2121): Caused by: java.lang.ClassNotFoundException: Didn't find class "org.joda.convert.FromString" on path: /data/app/com.nomotion.smsIntercept-1.apk
  04-22 13:12:35.762: E/AndroidRuntime(2121):     at dalvik.system.BaseDexClassLoader.findClass(BaseDexClassLoader.java:65)
  04-22 13:12:35.762: E/AndroidRuntime(2121):     at java.lang.ClassLoader.loadClass(ClassLoader.java:501)
  04-22 13:12:35.762: E/AndroidRuntime(2121):     at java.lang.ClassLoader.loadClass(ClassLoader.java:461)
  </code></pre>