Oh, I forgot my test program: ----------------------------------------- package test.exceptiontest;
import java.lang.Thread.UncaughtExceptionHandler; import android.app.Activity; import android.os.Bundle; import android.util.Log; public class ExceptionTest extends Activity { @Override public void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.main); MyExceptionHandler handler = new MyExceptionHandler (Thread.getDefaultUncaughtExceptionHandler()); Thread.setDefaultUncaughtExceptionHandler(handler); // // Exception handled correctly: // Thread t = new Thread() { @Override public void run() { throw new OutOfMemoryError("i am some nasty exception"); } }; t.start(); // // Exception jams UI: // throw new OutOfMemoryError("i am some nasty exception"); } private class MyExceptionHandler implements UncaughtExceptionHandler { private UncaughtExceptionHandler oldHandler; MyExceptionHandler(UncaughtExceptionHandler oldHandler) { this.oldHandler = oldHandler; } @Override public void uncaughtException(Thread thread, Throwable throwable) { Log.d("Debug", "Caught exception: " + throwable.getClass().getName () + ": " + throwable.getMessage()); // // This would use the default platform exception handler: // // oldHandler.uncaughtException(thread, throwable); } } } On 12 Aug., 09:56, Chronos <g358279012044...@gmail.com> wrote: > Hi all, > > in my application I would like to catch all exceptions globally - it > should not matter, where those exceptions occur. Some runtime > exceptions are practically impossible to catch (OutOfMemoryError for > instance), but I want to show an informative dialog and resume > execution at some well-defined point (main menu activity or > something). > > Using Thread.setDefaultUncaughtExceptionHandler() does this for > background threads, but it is of no help in the UI thread (or adjacent > handlers). If an exception occurs in the UI thread, the UI will be > jammed - not reacting to any key or touch events anymore. Of course, > this seems natural since it did not catch that exception; but I wonder > if there is a way to recover the UI thread. So: > > - Can I recover / restart the UI thread after an uncaught exception > (from another thread) ? > - Is there another way to catch uncaught exceptions globally ? > - Are there viable alternatives to handle this problem ? > > Thx in advance --~--~---------~--~----~------------~-------~--~----~ You received this message because you are subscribed to the Google Groups "Android Developers" group. To post to this group, send email to android-developers@googlegroups.com To unsubscribe from this group, send email to android-developers-unsubscr...@googlegroups.com For more options, visit this group at http://groups.google.com/group/android-developers?hl=en -~----------~----~----~----~------~----~------~--~---