List of usage examples for java.lang Thread setDefaultUncaughtExceptionHandler
public static void setDefaultUncaughtExceptionHandler(UncaughtExceptionHandler eh)
From source file:au.com.cybersearch2.classyjpa.entity.LoaderTaskImpl.java
/** * Execute persistence work in background thread * Called on a worker thread to perform the actual load. * @return Boolean object - Boolean.TRUE indicates successful result *//*w w w .j a va 2s . c o m*/ @Override public Boolean loadInBackground() { // Hook into UncaughtExceptionHandler chain final UncaughtExceptionHandler chain = Thread.getDefaultUncaughtExceptionHandler(); Thread.setDefaultUncaughtExceptionHandler(new Thread.UncaughtExceptionHandler() { @Override public void uncaughtException(Thread t, Throwable uncaughtException) { // Save exception for post-execution error handling LoaderTaskImpl.this.uncaughtException = uncaughtException; chain.uncaughtException(t, uncaughtException); } }); return persistenceContainer.executeInBackground(persistenceWork, transactionInfo); }
From source file:com.jeffthefate.stacktrace.ExceptionHandler.java
/** * Register handler for unhandled exceptions. * @param context/*from w ww. j a v a2 s .com*/ */ public static boolean register(Application app) { mCallback = (OnStacktraceListener) app; Log.i(TAG, "Registering default exceptions handler"); // Get information about the Package PackageManager pm = app.getPackageManager(); try { PackageInfo pi; // Version pi = pm.getPackageInfo(app.getPackageName(), 0); G.APP_VERSION = pi.versionName; // Package name G.APP_PACKAGE = pi.packageName; // Files dir for storing the stack traces G.FILES_PATH = app.getFilesDir().getAbsolutePath(); // Device model G.PHONE_MODEL = android.os.Build.MODEL; // Android version G.ANDROID_VERSION = android.os.Build.VERSION.RELEASE; } catch (NameNotFoundException e) { e.printStackTrace(); } Log.d(TAG, "APP_VERSION: " + G.APP_VERSION); Log.d(TAG, "APP_PACKAGE: " + G.APP_PACKAGE); Log.d(TAG, "FILES_PATH: " + G.FILES_PATH); boolean stackTracesFound = false; // We'll return true if any stack traces were found if (searchForStackTraces().length > 0) stackTracesFound = true; new Thread() { @Override public void run() { // First of all transmit any stack traces that may be lying around submitStackTraces(); UncaughtExceptionHandler currentHandler = Thread.getDefaultUncaughtExceptionHandler(); if (currentHandler != null) { Log.d(TAG, "current handler class=" + currentHandler.getClass().getName()); } // don't register again if already registered if (!(currentHandler instanceof DefaultExceptionHandler)) { // Register default exceptions handler Thread.setDefaultUncaughtExceptionHandler(new DefaultExceptionHandler(currentHandler)); } } }.start(); return stackTracesFound; }
From source file:com.reallynourl.nourl.fmpfoldermusicplayer.ui.activity.MainActivity.java
@Override protected void onCreate(Bundle savedInstanceState) { Thread.currentThread().setName("main"); Thread.setDefaultUncaughtExceptionHandler( new MyUncaughtExceptionHandler(Thread.getDefaultUncaughtExceptionHandler())); super.onCreate(savedInstanceState); setContentView(R.layout.activity_main); Toolbar toolbar = (Toolbar) findViewById(R.id.toolbar); setSupportActionBar(toolbar);/*from w w w . j ava2 s .co m*/ DrawerLayout drawer = (DrawerLayout) findViewById(R.id.drawer_layout); ActionBarDrawerToggle toggle = new ActionBarDrawerToggle(this, drawer, toolbar, R.string.navigation_drawer_open, R.string.navigation_drawer_close); drawer.setDrawerListener(toggle); toggle.syncState(); NavigationView navigationView = (NavigationView) findViewById(R.id.nav_view); navigationView.setNavigationItemSelectedListener(this); mCloseSnackBar = Snackbar.make(findViewById(android.R.id.content), "Press again to exit ...", Snackbar.LENGTH_SHORT); if (MediaManager.getInstance() == null) { MediaManager.create(getApplicationContext()); } if (savedInstanceState != null) { mActiveContentSavedName = savedInstanceState.getString(SAVED_INSTANCE_FRAGMENT, null); } }
From source file:org.stenerud.kscrash.KSCrash.java
/** Install the crash reporter. * * @param context The application context. *//*from www .ja v a 2 s . c o m*/ public void install(Context context) throws IOException { String appName = context.getApplicationInfo().processName; File installDir = new File(context.getCacheDir().getAbsolutePath(), "KSCrash"); install(appName, installDir.getCanonicalPath()); // TODO: Put this elsewhere oldUncaughtExceptionHandler = Thread.getDefaultUncaughtExceptionHandler(); Thread.setDefaultUncaughtExceptionHandler(new Thread.UncaughtExceptionHandler() { @Override public void uncaughtException(Thread t, Throwable e) { KSCrash.this.reportJavaException(e); KSCrash.oldUncaughtExceptionHandler.uncaughtException(t, e); } }); }
From source file:com.netdoers.zname.errorreporting.ExceptionHandler.java
/** * Register handler for unhandled exceptions. * @param context/* w w w .java 2 s . c o m*/ */ public static boolean register(Context context) { Log.i(TAG, "Registering default exceptions handler"); // Get information about the Package PackageManager pm = context.getPackageManager(); try { PackageInfo pi; // Version pi = pm.getPackageInfo(context.getPackageName(), 0); G.APP_VERSION = pi.versionName; // Version Code name G.APP_VERSION_CODE = String.valueOf(pi.versionCode);//ADDED VERSION CODE // Package name G.APP_PACKAGE = pi.packageName; // Files dir for storing the stack traces G.FILES_PATH = context.getFilesDir().getAbsolutePath(); // Device model G.PHONE_MODEL = android.os.Build.MODEL; // Device Size G.PHONE_SIZE = Zname.getPreferences().getDeviceSize(); // Android version G.ANDROID_VERSION = android.os.Build.VERSION.RELEASE; } catch (NameNotFoundException e) { e.printStackTrace(); } Log.i(TAG, "TRACE_VERSION: " + G.TraceVersion); Log.d(TAG, "APP_VERSION: " + G.APP_VERSION); Log.d(TAG, "APP_VERSION_CODE: " + G.APP_VERSION_CODE);//ADDED VERSION CODE Log.d(TAG, "APP_PACKAGE: " + G.APP_PACKAGE); Log.d(TAG, "FILES_PATH: " + G.FILES_PATH); Log.d(TAG, "URL: " + G.URL); boolean stackTracesFound = false; // We'll return true if any stack traces were found if (searchForStackTraces().length > 0) { stackTracesFound = true; } new Thread() { @Override public void run() { // First of all transmit any stack traces that may be lying around submitStackTraces(); UncaughtExceptionHandler currentHandler = Thread.getDefaultUncaughtExceptionHandler(); if (currentHandler != null) { Log.d(TAG, "current handler class=" + currentHandler.getClass().getName()); } // don't register again if already registered if (!(currentHandler instanceof DefaultExceptionHandler)) { // Register default exceptions handler Thread.setDefaultUncaughtExceptionHandler(new DefaultExceptionHandler(currentHandler)); } } }.start(); return stackTracesFound; }
From source file:com.netdoers.com.stacktrace.ExceptionHandler.java
/** * Register handler for unhandled exceptions. * @param context/* www . ja va 2 s . c om*/ */ public static boolean register(Context context) { Log.i(TAG, "Registering default exceptions handler"); // Get information about the Package PackageManager pm = context.getPackageManager(); try { PackageInfo pi; // Version pi = pm.getPackageInfo(context.getPackageName(), 0); G.APP_VERSION = pi.versionName; // Version Code name G.APP_VERSION_CODE = String.valueOf(pi.versionCode);//ADDED VERSION CODE // Package name G.APP_PACKAGE = pi.packageName; // Files dir for storing the stack traces G.FILES_PATH = context.getFilesDir().getAbsolutePath(); // Device model G.PHONE_MODEL = android.os.Build.MODEL; // Device Size G.PHONE_SIZE = SmartConsultant.getPreferences().getDeviceSize(); // Android version G.ANDROID_VERSION = android.os.Build.VERSION.RELEASE; } catch (NameNotFoundException e) { e.printStackTrace(); } Log.i(TAG, "TRACE_VERSION: " + G.TraceVersion); Log.d(TAG, "APP_VERSION: " + G.APP_VERSION); Log.d(TAG, "APP_VERSION_CODE: " + G.APP_VERSION_CODE);//ADDED VERSION CODE Log.d(TAG, "APP_PACKAGE: " + G.APP_PACKAGE); Log.d(TAG, "FILES_PATH: " + G.FILES_PATH); Log.d(TAG, "URL: " + G.URL); boolean stackTracesFound = false; // We'll return true if any stack traces were found if (searchForStackTraces().length > 0) { stackTracesFound = true; } new Thread() { @Override public void run() { // First of all transmit any stack traces that may be lying around submitStackTraces(); UncaughtExceptionHandler currentHandler = Thread.getDefaultUncaughtExceptionHandler(); if (currentHandler != null) { Log.d(TAG, "current handler class=" + currentHandler.getClass().getName()); } // don't register again if already registered if (!(currentHandler instanceof DefaultExceptionHandler)) { // Register default exceptions handler Thread.setDefaultUncaughtExceptionHandler(new DefaultExceptionHandler(currentHandler)); } } }.start(); return stackTracesFound; }
From source file:com.BeeFramework.activity.MainActivity.java
public void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); shared = this.getSharedPreferences("userInfo", 0); editor = shared.edit();/* w w w .j ava 2s.com*/ String path = Environment.getExternalStorageDirectory().getAbsolutePath() + AppConst.LOG_DIR_PATH; File storePath = new File(path); storePath.mkdirs(); Thread.setDefaultUncaughtExceptionHandler(new CustomExceptionHandler(path, null)); }
From source file:com.gotraveling.insthub.BeeFramework.activity.MainActivity.java
public void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); shared = this.getSharedPreferences("userInfo", 0); editor = shared.edit();/*from w w w .j av a 2 s .c o m*/ String path = Environment.getExternalStorageDirectory().getAbsolutePath() + BeeFrameworkConst.LOG_DIR_PATH; File storePath = new File(path); storePath.mkdirs(); Thread.setDefaultUncaughtExceptionHandler(new CustomExceptionHandler(path, null)); }
From source file:com.application.error.ExceptionHandler.java
/** * Register handler for unhandled exceptions. * @param context//from w w w . ja v a 2s. c o m */ public static boolean register(Context context) { Log.i(TAG, "Registering default exceptions handler"); // Get information about the Package PackageManager pm = context.getPackageManager(); try { PackageInfo pi; // Version pi = pm.getPackageInfo(context.getPackageName(), 0); G.APP_VERSION = pi.versionName; // Version Code name G.APP_VERSION_CODE = String.valueOf(pi.versionCode);//ADDED VERSION CODE // Package name G.APP_PACKAGE = pi.packageName; // Files dir for storing the stack traces G.FILES_PATH = context.getFilesDir().getAbsolutePath(); // Device model G.PHONE_MODEL = android.os.Build.MODEL; // Device Size try { G.PHONE_SIZE = String.valueOf(Utilities.checkDisplaySize()); } catch (Exception e) { G.PHONE_SIZE = "DEVICE SIZE NOT FOUND"; } // Android version G.ANDROID_VERSION = android.os.Build.VERSION.RELEASE; } catch (NameNotFoundException e) { e.printStackTrace(); } Log.i(TAG, "TRACE_VERSION: " + G.TraceVersion); Log.d(TAG, "APP_VERSION: " + G.APP_VERSION); Log.d(TAG, "APP_VERSION_CODE: " + G.APP_VERSION_CODE);//ADDED VERSION CODE Log.d(TAG, "APP_PACKAGE: " + G.APP_PACKAGE); Log.d(TAG, "FILES_PATH: " + G.FILES_PATH); Log.d(TAG, "URL: " + G.URL); boolean stackTracesFound = false; // We'll return true if any stack traces were found if (searchForStackTraces().length > 0) { stackTracesFound = true; } new Thread() { @Override public void run() { // First of all transmit any stack traces that may be lying around submitStackTraces(); UncaughtExceptionHandler currentHandler = Thread.getDefaultUncaughtExceptionHandler(); if (currentHandler != null) { Log.d(TAG, "current handler class=" + currentHandler.getClass().getName()); } // don't register again if already registered if (!(currentHandler instanceof DefaultExceptionHandler)) { // Register default exceptions handler Thread.setDefaultUncaughtExceptionHandler(new DefaultExceptionHandler(currentHandler)); } } }.start(); return stackTracesFound; }
From source file:com.hippo.ehviewer.EhApplication.java
@Override public void onCreate() { // Prepare to catch crash mDefaultHandler = Thread.getDefaultUncaughtExceptionHandler(); Thread.setDefaultUncaughtExceptionHandler(this); super.onCreate(); GetText.initialize(this); CookieDB.initialize(this); StatusCodeException.initialize(this); Settings.initialize(this); ReadableTime.initialize(this); Html.initialize(this); AppConfig.initialize(this); SpiderDen.initialize(this); EhDB.initialize(this); EhEngine.initialize();//w w w .j a va 2 s . c o m BitmapUtils.initialize(this); if (EhDB.needMerge()) { EhDB.mergeOldDB(this); } if (Settings.getEnableAnalytics()) { Analytics.start(this); } // Check no media file UniFile downloadLocation = Settings.getDownloadLocation(); if (Settings.getMediaScan()) { CommonOperations.removeNoMediaFile(downloadLocation); } else { CommonOperations.ensureNoMediaFile(downloadLocation); } // Clear temp dir clearTempDir(); // Check app update update(); // Update version code try { PackageInfo pi = getPackageManager().getPackageInfo(getPackageName(), 0); Settings.putVersionCode(pi.versionCode); } catch (PackageManager.NameNotFoundException e) { // Ignore } if (DEBUG_PRINT_NATIVE_MEMORY || DEBUG_PRINT_IMAGE_COUNT) { debugPrint(); } }