List of usage examples for java.lang Thread getDefaultUncaughtExceptionHandler
public static UncaughtExceptionHandler getDefaultUncaughtExceptionHandler()
From source file:ThreadDemo.java
public void run() { System.out.println("Thread = " + getName()); Thread.UncaughtExceptionHandler handler = Thread.getDefaultUncaughtExceptionHandler(); System.out.println(handler);// w ww. ja v a2s. c o m }
From source file:com.spotify.helios.system.AgentStateDirConflictTest.java
@Before public void setup() throws Exception { zk = new ZooKeeperTestingServerManager(); dueh = Thread.getDefaultUncaughtExceptionHandler(); Thread.setDefaultUncaughtExceptionHandler(new Thread.UncaughtExceptionHandler() { @Override//from w w w . ja v a2s. c o m public void uncaughtException(final Thread t, final Throwable e) { } }); stateDir = Files.createTempDirectory("helios-agent-conflict-test"); first = makeAgent("first"); second = makeAgent("second"); }
From source file:at.wada811.android.library.demos.CrashExceptionHandler.java
public CrashExceptionHandler(Context context) { mContext = context; mHandler = Thread.getDefaultUncaughtExceptionHandler(); }
From source file:com.altcanvas.twitspeak.TwitSpeakActivity.java
@Override public void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); systemDefaultUEH = Thread.getDefaultUncaughtExceptionHandler(); Thread.setDefaultUncaughtExceptionHandler(new TopExceptionHandler(this)); setContentView(R.layout.main);/*ww w. ja v a 2s . c o m*/ boolean hasStackTrace = checkStackTrace(); if (!hasStackTrace) continueOnCreate(); }
From source file:cc.metapro.openct.utils.CrashHandler.java
private void init(OpenCT context) { mDefaultHandler = Thread.getDefaultUncaughtExceptionHandler(); Thread.setDefaultUncaughtExceptionHandler(this); mContext = context;/*from w ww. ja va 2 s . c om*/ }
From source file:org.apache.hadoop.hdfs.TestFileCreationEmpty.java
/** * This test creates three empty files and lets their leases expire. * This triggers release of the leases. * The empty files are supposed to be closed by that * without causing ConcurrentModificationException. */// w w w .j av a 2s . c o m public void testLeaseExpireEmptyFiles() throws Exception { final Thread.UncaughtExceptionHandler oldUEH = Thread.getDefaultUncaughtExceptionHandler(); Thread.setDefaultUncaughtExceptionHandler(new Thread.UncaughtExceptionHandler() { public void uncaughtException(Thread t, Throwable e) { if (e instanceof ConcurrentModificationException) { LeaseManager.LOG.error("t=" + t, e); isConcurrentModificationException = true; } } }); LOG.info("testLeaseExpireEmptyFiles start"); final long leasePeriod = 1000; final int DATANODE_NUM = 3; final Configuration conf = new HdfsConfiguration(); conf.setInt(DFSConfigKeys.DFS_NAMENODE_HEARTBEAT_RECHECK_INTERVAL_KEY, 1000); conf.setInt(DFSConfigKeys.DFS_HEARTBEAT_INTERVAL_KEY, 1); // create cluster MiniDFSCluster cluster = new MiniDFSCluster.Builder(conf).numDataNodes(DATANODE_NUM).build(); try { cluster.waitActive(); DistributedFileSystem dfs = (DistributedFileSystem) cluster.getFileSystem(); // create a new file. TestFileCreation.createFile(dfs, new Path("/foo"), DATANODE_NUM); TestFileCreation.createFile(dfs, new Path("/foo2"), DATANODE_NUM); TestFileCreation.createFile(dfs, new Path("/foo3"), DATANODE_NUM); // set the soft and hard limit to be 1 second so that the // namenode triggers lease recovery cluster.setLeasePeriod(leasePeriod, leasePeriod); // wait for the lease to expire try { Thread.sleep(5 * leasePeriod); } catch (InterruptedException e) { } assertFalse(isConcurrentModificationException); } finally { Thread.setDefaultUncaughtExceptionHandler(oldUEH); cluster.shutdown(); } }
From source file:de.schildbach.wallet.util.CrashReporter.java
public static void init(final File cacheDir) { backgroundTracesFile = new File(cacheDir, BACKGROUND_TRACES_FILENAME); crashTraceFile = new File(cacheDir, CRASH_TRACE_FILENAME); Thread.setDefaultUncaughtExceptionHandler( new ExceptionHandler(Thread.getDefaultUncaughtExceptionHandler())); }
From source file:com.atinternet.tracker.CrashDetectionHandlerTest.java
@Before public void setUp() throws Exception { super.setUp(); crashDetectionHandler = new CrashDetectionHandler(Robolectric.application, Thread.getDefaultUncaughtExceptionHandler()); preferences = Robolectric.application.getSharedPreferences(TrackerConfigurationKeys.PREFERENCES, android.content.Context.MODE_PRIVATE); }
From source file:org.andicar.service.UpdateCheckService.java
@Override public void onStart(Intent intent, int startId) { super.onStart(intent, startId); if (getSharedPreferences(StaticValues.GLOBAL_PREFERENCE_NAME, Context.MODE_MULTI_PROCESS) .getBoolean("SendCrashReport", true)) Thread.setDefaultUncaughtExceptionHandler( new AndiCarExceptionHandler(Thread.getDefaultUncaughtExceptionHandler(), this)); try {/* ww w . j a v a2 s . c o m*/ Bundle extras = intent.getExtras(); if (extras == null || extras.getBoolean("setJustNextRun") || !extras.getBoolean("AutoUpdateCheck")) { setNextRun(); stopSelf(); } URL updateURL = new URL(StaticValues.VERSION_FILE_URL); URLConnection conn = updateURL.openConnection(); if (conn == null) return; InputStream is = conn.getInputStream(); if (is == null) return; BufferedInputStream bis = new BufferedInputStream(is); ByteArrayBuffer baf = new ByteArrayBuffer(50); int current = 0; while ((current = bis.read()) != -1) { baf.append((byte) current); } /* Convert the Bytes read to a String. */ String s = new String(baf.toByteArray()); /* Get current Version Number */ int curVersion = getPackageManager().getPackageInfo("org.andicar.activity", 0).versionCode; int newVersion = Integer.valueOf(s); /* Is a higher version than the current already out? */ if (newVersion > curVersion) { //get the whats new message updateURL = new URL(StaticValues.WHATS_NEW_FILE_URL); conn = updateURL.openConnection(); if (conn == null) return; is = conn.getInputStream(); if (is == null) return; bis = new BufferedInputStream(is); baf = new ByteArrayBuffer(50); current = 0; while ((current = bis.read()) != -1) { baf.append((byte) current); } /* Convert the Bytes read to a String. */ s = new String(baf.toByteArray()); mNM = (NotificationManager) getSystemService(NOTIFICATION_SERVICE); notification = null; Intent i = new Intent(this, WhatsNewDialog.class); i.putExtra("UpdateMsg", s); PendingIntent contentIntent = PendingIntent.getActivity(UpdateCheckService.this, 0, i, 0); CharSequence title = getText(R.string.Notif_UpdateTitle); String message = getString(R.string.Notif_UpdateMsg); notification = new Notification(R.drawable.icon_sys_info, message, System.currentTimeMillis()); notification.flags |= Notification.DEFAULT_LIGHTS; notification.flags |= Notification.DEFAULT_SOUND; notification.flags |= Notification.FLAG_AUTO_CANCEL; notification.setLatestEventInfo(UpdateCheckService.this, title, message, contentIntent); mNM.notify(StaticValues.NOTIF_UPDATECHECK_ID, notification); setNextRun(); } stopSelf(); } catch (Exception e) { Log.i("UpdateService", "Service failed."); e.printStackTrace(); } }
From source file:com.hybris.mobile.logging.ExceptionHandler.java
public static boolean register(Context context) { LoggingUtils.i(LOG_TAG, "Registering default exceptions handler"); // Get information about the Package PackageManager pm = context.getPackageManager(); try {/*from www .j a v a2 s . c o m*/ PackageInfo pi; // Version pi = pm.getPackageInfo(context.getPackageName(), 0); RA.APP_VERSION = pi.versionName; // Package name RA.APP_PACKAGE = pi.packageName; // Files dir for storing the stack traces RA.FILES_PATH = context.getFilesDir().getAbsolutePath(); // Device model RA.PHONE_MODEL = android.os.Build.MODEL; // Android version RA.ANDROID_VERSION = android.os.Build.VERSION.RELEASE; } catch (NameNotFoundException e) { LoggingUtils.e(LOG_TAG, "No package found for \"" + context.getPackageName() + "\"" + e.getLocalizedMessage(), context); } LoggingUtils.i(LOG_TAG, "TRACE_VERSION: " + RA.TraceVersion); LoggingUtils.d(LOG_TAG, "APP_VERSION: " + RA.APP_VERSION); LoggingUtils.d(LOG_TAG, "APP_PACKAGE: " + RA.APP_PACKAGE); LoggingUtils.d(LOG_TAG, "FILES_PATH: " + RA.FILES_PATH); LoggingUtils.d(LOG_TAG, "URL: " + RA.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) { LoggingUtils.d(LOG_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; }