android - Rethrow UncaughtExceptionHandler Exception after Logging It -
android - Rethrow UncaughtExceptionHandler Exception after Logging It -
in application class trying grab forcefulness close before happens, can log , rethrow android can handle it. since users not study forcefulness closes.
i developing in eclipse, , eclipse not allowing me rethrow exception. shows error saying "unhandled exception type throwable: surround try/catch". how can rethrow exception?
public class mainapplication extends application { @override public void oncreate() { super.oncreate(); seek { //log exception before app forcefulness closes thread.currentthread().setuncaughtexceptionhandler(new uncaughtexceptionhandler() { @override public void uncaughtexception(thread thread, throwable ex) { analyticsutils.getinstance(mainapplication.this).trackevent( "errors", // category "mainactivity", // action "force close: "+ex.tostring(), // label 0); // value analyticsutils.getinstance(mainapplication.this).dispatch(); toast.maketext(mainapplication.this, "snap! broke. please study forcefulness close can prepare it.", toast.length_long); //rethrow exception user can study //throw ex; //<-- **eclipse showing error surround try/catch** } }); } grab (exception e) { e.printstacktrace(); } }
}
apologies, not android expert - looks can't throw ex because method signature "void uncaughtexception(thread, throwable)" doesn't declare "throws" anything.
assuming you're overriding api interface , (a) can't modify signature , (b) don't want because you'd throwing out of context, instead utilize decorator pattern , subclass default uncaughtexceptionhandler implementation log message , allow carry on processing usual?
edit: untested, might bit like:
final uncaughtexceptionhandler subclass = thread.currentthread().getuncaughtexceptionhandler(); thread.currentthread().setuncaughtexceptionhandler(new uncaughtexceptionhandler() { @override public void uncaughtexception(thread thread, throwable ex) { // code analyticsutils.getinstance(mainapplication.this).trackevent( "errors", // category "mainactivity", // action "force close: "+ex.tostring(), // label 0); // value analyticsutils.getinstance(mainapplication.this).dispatch(); toast.maketext(mainapplication.this, "snap! broke. please study forcefulness close can prepare it.", toast.length_long); // carry on prior flow subclass.uncaughtexception(thread, ex); } });
android eclipse exception exception-handling
Comments
Post a Comment