Inherit the UncaughtExceptionHandler interface, and overwrite the uncaughtException (Thread thread, Throwable ex) method in it. In this way, you can monitor application exceptions and perform corresponding processing:
Public class myCustomExceptionHandler implements UncaughtExceptionHandler {
Private UncaughtExceptionHandler defaultUEH;
Public myCustomExceptionHandler (){
This. defaultUEH = Thread. getDefaultUncaughtExceptionHandler ();
}
@ Override
Public void uncaughtException (Thread thread, Throwable ex ){
// TODO Auto-generated method stub
System. out. println ("application exception ");
/**
* Handle exceptions. Save the exception log or send an exception report to the server.
*/
DefaultUEH. uncaughtException (thread, ex );;
}
}
Then add Thread. setDefaultUncaughtExceptionHandler (new myCustomExceptionHandler (); to the Activity.
Author: Koon. LY