java - Crash app in Thread.setDefaultUncaughtExceptionHandler -
i crash app on purpose after logging own error. handler registered in application.oncreate():
// set global exception handler thread.setdefaultuncaughtexceptionhandler(new uncaughtexceptionhandler() { @override public void uncaughtexception(thread thread, final throwable ex) { // unregister thread.setdefaultuncaughtexceptionhandler(null); // report ... // crash app -does not work, app frozen if (ex instanceof runtimeexception) throw (runtimeexception) ex; throw new runtimeexception("re-throw", ex); }
however, app freezes instead of crashing dialog. how can crash application if hadn't registered handler?
this bit of code never going work.
an uncaught exception handler called after thread has terminated due exception not caught. if attempt re-throw exception, there nothing else catch it.
if want have re-thrown exception handled in normal, have logging further stack.
the other option have explicitly chain
uncaughtexceptionhandler
.
i suspect freeze experiencing direct consequence of current thread dying.
followup:
... there other way in android intercept exceptions @ global level, without using thread.setdefaultuncaughtexceptionhandler?
afaik, no.
or how chaining like?
something this:
public void uncaughtexception(thread thread, final throwable ex) { // report ... getsomeotherhandler(...).uncaughtexception(thread, ex); }
or, since threadgroup implements uncaughtexceptionhandler
, ...
public void uncaughtexception(thread thread, final throwable ex) { // report ... thread.getthreadgoup().uncaughtexception(thread, ex); }
basically, call other handler. it's not rocket science.
but note can't catch , recover exception in "normal" way once you've landed in 1 of these handlers.
Comments
Post a Comment