Best practices for capturing unhandle runtime Exception for JAVA on Android os?

During the process that works for me during the e3roid scene population on android, I always encounter exceptions that I want to completely capture. Perhaps I need to create a reverse tracker to track exceptions, which I can pass through my leisure time instead of an immediate dialogue that takes away the user's experience.

W/dalvikvm( 9540): threadid=1: thread exiting with uncaught exception (group=0x2 aac87c8) E/AndroidRuntime( 9540): FATAL EXCEPTION: main E/AndroidRuntime( 9540): java.util.ConcurrentModificationException E/AndroidRuntime( 9540): at java.util.ArrayList$ArrayListIterator.next(Ar rayList.java:573) 

the entire application dies with an exception dialog .. I would like to catch a ConcurrentModificationException from the global scope, so that if such an event occurs due to unknown circumstances, the entire application is not deleted ..

** EDIT **

while blocking this block during onSceneTouchEvent

 try { postUpdate(new AddShapeImpl(scene, onX, onY)); } finally { } 

It seems like I'm firing the block too fast, I think. I need to slow down the work.

* Follow Up *

It seemed to me that the problem was solved. I made one of them ...

 if ( ballspawning == false) try { Log.v(DEBUG_TAG, "onSceneTouchEvent 1-1"); addnewball(scene, onX, onY); Log.v(DEBUG_TAG, "onSceneTouchEvent 1-2"); } finally { } 

You will see that after I entered the ball with the Boolean flag, and the secondary procedure that I pass, my spawning grounds were so golden ... I made this field, and it is set at the end of my iteration and checked before the transverse list happens. . whoo hoo !! soo sweet!

there is no real need for global capture .. just a good old debugging. but I would still like to implement a global handler for all errors. Todo

I again caused a parallel error.

Screenshots

Debug Msgs

Other incident

screenshot 4

almost narrows the culprit

I tried to catch ConcurrentModificationException with

  void uncaughtException(Thread t, Throwable e){ Log.v(DEBUG_TAG, "uncaughtException **********"); Log.v(DEBUG_TAG,"thread " + t + " Throwable" + e.toString()); } 

as you can see in the last screenshot, the above method is never called.

The ConcurrentModificationException parameter splits the application into an exception dialog.

** Following actions **

I added

 public class LauncherActivity extends E3Activity implements UncaughtExceptionHandler ,FPSListener,SceneUpdateListener 

and at run time an additional Unimplimented Method

 @Override public void uncaughtException(Thread t,Throwable e) { Log.v(DEBUG_TAG, "uncaughtException **************"); Log.v(DEBUG_TAG,"thread " + t + " Throwable" + e.toString()); } 

and still does not contain exception capture ...

I also added

 newThread.setUncaughtExceptionHandler(new Thread.UncaughtExceptionHandler(){ @Override public void uncaughtException(Thread t, Throwable e) { Log.v(DEBUG_TAG,"*************** ERROR! An exception occurred in " + t.getName() + ". Cause: " + e.getMessage()); } }); newThread.start(); 

and still not exciting ...

aaaa

WHoo hoo !!

Just caught the exception !! check the screenshot ... you will see !!!!!!

http://img17.imageshack.us/img17/135/concurrentmodificatione.png

Caught Exception

thanks all that made me work hard to figure out java exception handling!

Great resource

I caught the concurrency issue on

removal ...

Public class LauncherActivity extends E3Activity implements UncaughtExceptionHandler, FPSListener, SceneUpdateListener

that I had the original ... without implementing UncaughtExceptionHandler

and added a class that Johnny Lee described in great detail. blog.dimond.de/?p=63

Sweet stuff.

+4
source share
2 answers

Use Thread.setUncaughtExceptionHandler :

As an argument, which is the interface of a single method, Thread.UncaughtExceptionHandler : uncaughtException(Thread t, Throwable e) .

From the documentation:

Install a handler called when this thread terminates abruptly due to an uncaught exception.

Of course, however, you are obviously better off fixing exceptions in your sources. ;-) However, I use this construct to send error reports in case of unexpected errors.

+2
source

I think you are more likely to make sure that ConcurrentModificationException does not occur at all.

This exception occurs when you iterate through a Collection using an Iterator . During iteration, you cannot update the collection. Here is the scenario in which it will arise:

 List<Integer> intList = new ArrayList<Integer>(); for (int i=0; i < 100; ++i) { intList.add(i); } int addValue = 1000; for (Integer i: intList) { if (i%10 == 0) { //get ready for ConcurrentModificationException... intList.add(++addValue);//this is bad, because we are iterating over intList. } } 

This will throw a ConcurrentModificationException, because we are repeating the list and trying to add to it while this iteration happens.

+2
source

All Articles