1 Packagecom.example.administrator.mystudent;2 3 Importandroid.app.Application;4 ImportAndroid.util.Log;5 6 Importorg.xutils.x;7 8 /**9 * Created by Hyang on 2016/8/23.Ten */ One Public classMyApplicationextendsApplication { A Private Static FinalString TAG = "Global" ; - - @Override the Public voidonCreate () { - Super. OnCreate (); - //Initialize Xutils -X.ext.init ( This); + //Output Debugging Information -X.ext.setdebug (true); + getanyexception (); A } at - /** - * Captures any global exception - */ - Private voidgetanyexception () { -Thread.setdefaultuncaughtexceptionhandler (NewThread.uncaughtexceptionhandler () { in @Override - Public voiduncaughtexception (thread thread, Throwable ex) { to ex.printstacktrace (); +LOG.E (TAG, "catch to Exception" +ex.tostring ()); - //1. Store the caught exception in a local file the //2. Handle uploading the exception file to the server * //3. Exit the app normally (avoid the popup dialog to force exit) $System.exit (0);Panax Notoginseng } - }); the } +}
Capturing global exceptions in the app in application