List of usage examples for java.lang Thread getDefaultUncaughtExceptionHandler
public static UncaughtExceptionHandler getDefaultUncaughtExceptionHandler()
From source file:org.wso2.carbon.automation.extensions.jmeter.JMeterTestManager.java
private String executeTest(File test) throws Exception { String reportFileName;/*www .j av a2 s .c om*/ String reportFileFullPath; JMeter jmeterInstance = new JMeter(); try { log.info("Executing test: " + test.getCanonicalPath()); reportFileName = test.getName().substring(0, test.getName().lastIndexOf(".")) + "-" + fmt.format(new Date()) + ".jmeterResult" + ".jtl"; File reportDir = JMeterInstallationProvider.getInstance().getReportDir(); reportFileFullPath = reportDir.toString() + File.separator + reportFileName; List<String> argsTmp = Arrays.asList("-n", "-t", test.getCanonicalPath(), "-l", reportDir.toString() + File.separator + reportFileName, "-p", jmeterProps.toString(), "-d", jmeterHome.getCanonicalPath(), "-L", "jorphan=" + jmeterLogLevel, "-L", "jmeter.util=" + jmeterLogLevel); List<String> args = new ArrayList<String>(); args.addAll(argsTmp); SecurityManager oldManager = System.getSecurityManager(); UncaughtExceptionHandler oldHandler = Thread.getDefaultUncaughtExceptionHandler(); Thread.setDefaultUncaughtExceptionHandler(new UncaughtExceptionHandler() { public void uncaughtException(Thread t, Throwable e) { if (e instanceof ExitException && ((ExitException) e).getCode() == 0) { return; //Ignore } log.error("Error in thread " + t.getName()); } }); try { logParamsAndProps(args); jmeterInstance.start(args.toArray(new String[] {})); BufferedReader in = new BufferedReader( new InputStreamReader(new FileInputStream(jmeterLogFile), Charset.defaultCharset())); while (!checkForEndOfTest(in)) { try { Thread.sleep(1000); } catch (InterruptedException e) { break; } } } catch (ExitException e) { if (e.getCode() != 0) { throw new Exception("Test failed", e); } } catch (Exception e) { log.error(e); } finally { System.setSecurityManager(oldManager); Thread.setDefaultUncaughtExceptionHandler(oldHandler); } } catch (IOException e) { throw new Exception("Can't execute test", e); } return reportFileFullPath; }
From source file:com.javielinux.tweettopics2.TweetTopicsActivity.java
@Override public void onCreate(Bundle savedInstanceState) { try {/*from w w w . j a v a 2 s . c om*/ DataFramework.getInstance().open(this, Utils.packageName); } catch (Exception e) { e.printStackTrace(); } super.onCreate(savedInstanceState); CacheData.getInstance().fillHide(); ConnectionManager.getInstance().open(this); ConnectionManager.getInstance().loadUsers(); OnAlarmReceiver.callAlarm(this); if (PreferenceUtils.getFinishForceClose(this)) { PreferenceUtils.setFinishForceClose(this, false); AlertDialog.Builder builder = new AlertDialog.Builder(this); builder.setTitle(R.string.title_crash); builder.setMessage(R.string.msg_crash); builder.setPositiveButton(R.string.alert_dialog_ok, new DialogInterface.OnClickListener() { public void onClick(DialogInterface dialog, int whichButton) { Utils.sendLastCrash(TweetTopicsActivity.this); } }); builder.setNegativeButton(R.string.alert_dialog_cancel, new DialogInterface.OnClickListener() { public void onClick(DialogInterface dialog, int whichButton) { } }); builder.create(); builder.show(); } Thread.UncaughtExceptionHandler currentHandler = Thread.getDefaultUncaughtExceptionHandler(); if (currentHandler != null) { Thread.setDefaultUncaughtExceptionHandler(new ErrorReporter(currentHandler, getApplication())); } if (PreferenceManager.getDefaultSharedPreferences(this).getString("prf_orientation", "2").equals("2")) { setRequestedOrientation(ActivityInfo.SCREEN_ORIENTATION_SENSOR); } // borrar notificaciones if (PreferenceManager.getDefaultSharedPreferences(this).getBoolean("prf_notif_delete_notifications_inside", true)) { ((NotificationManager) getSystemService(Context.NOTIFICATION_SERVICE)).cancelAll(); } long goToColumnPosition = -1; int goToColumnType = -1; long goToColumnUser = -1; long goToColumnSearch = -1; long selectedTweetId = -1; Bundle extras = getIntent().getExtras(); if (extras != null) { if (extras.containsKey(KEY_EXTRAS_GOTO_COLUMN_POSITION)) { goToColumnPosition = extras.getLong(KEY_EXTRAS_GOTO_COLUMN_POSITION); } if (extras.containsKey(KEY_EXTRAS_GOTO_COLUMN_TYPE)) { goToColumnType = extras.getInt(KEY_EXTRAS_GOTO_COLUMN_TYPE); } if (extras.containsKey(KEY_EXTRAS_GOTO_COLUMN_USER)) { goToColumnUser = extras.getLong(KEY_EXTRAS_GOTO_COLUMN_USER); } if (extras.containsKey(KEY_EXTRAS_GOTO_COLUMN_SEARCH)) { goToColumnSearch = extras.getLong(KEY_EXTRAS_GOTO_COLUMN_SEARCH); } if (extras.containsKey(KEY_EXTRAS_GOTO_TWEET_ID)) { selectedTweetId = extras.getLong(KEY_EXTRAS_GOTO_TWEET_ID); } } int positionFromSensor = -1; if (savedInstanceState != null && savedInstanceState.containsKey(KEY_SAVE_STATE_COLUMN_POS)) { positionFromSensor = savedInstanceState.getInt(KEY_SAVE_STATE_COLUMN_POS); } Utils.createDirectoriesIfIsNecessary(); Display display = getWindowManager().getDefaultDisplay(); widthScreen = display.getWidth(); heightScreen = display.getHeight(); themeManager = new ThemeManager(this); themeManager.setTheme(); setContentView(R.layout.tweettopics_activity); fragmentAdapter = new TweetTopicsFragmentAdapter(this, getSupportFragmentManager()); pager = (ViewPager) findViewById(R.id.tweet_pager); pager.setAdapter(fragmentAdapter); indicator = (TitlePageIndicator) findViewById(R.id.tweettopics_bar_indicator); indicator.setFooterIndicatorStyle(TitlePageIndicator.IndicatorStyle.Triangle); indicator.setFooterLineHeight(0); indicator.setFooterColor(Color.WHITE); indicator.setClipPadding(-getWindowManager().getDefaultDisplay().getWidth()); indicator.setViewPager(pager); indicator.setOnPageChangeListener(new ViewPager.OnPageChangeListener() { @Override public void onPageScrolled(int i, float v, int i1) { } @Override public void onPageSelected(int i) { reloadBarAvatar(); if (i == 0) { refreshMyActivity(); } } @Override public void onPageScrollStateChanged(int i) { } }); indicator.setOnClickListener(new View.OnClickListener() { @Override public void onClick(View view) { showActionBarColumns(); } }); findViewById(R.id.tweettopics_bar_my_activity).setOnClickListener(new View.OnClickListener() { @Override public void onClick(View view) { showActionBarIndicatorAndMovePager(0); } }); findViewById(R.id.tweettopics_bar_options).setOnClickListener(new View.OnClickListener() { @Override public void onClick(View view) { showMenuColumnsOptions(view); } }); layoutOptionsColumns = (LinearLayout) findViewById(R.id.tweettopics_ll_options_columns); layoutMainOptionsColumns = (LinearLayout) findViewById(R.id.tweettopics_ll_main_options_columns); layoutMainOptionsColumns.setOnClickListener(new View.OnClickListener() { @Override public void onClick(View view) { hideOptionsColumns(); } }); btnOptionsColumnsMain = (Button) findViewById(R.id.tweettopics_ll_options_columns_btn_main); btnOptionsColumnsMain.setOnClickListener(new View.OnClickListener() { @Override public void onClick(View view) { int pos = Integer.valueOf(view.getTag().toString()); Toast.makeText(TweetTopicsActivity.this, getString(R.string.column_main_message, fragmentAdapter.setColumnActive(pos)), Toast.LENGTH_LONG).show(); hideOptionsColumns(); } }); btnOptionsColumnsEdit = (Button) findViewById(R.id.tweettopics_ll_options_columns_btn_edit); btnOptionsColumnsEdit.setOnClickListener(new View.OnClickListener() { @Override public void onClick(View view) { int pos = Integer.valueOf(view.getTag().toString()); EditColumnDialogFragment frag = new EditColumnDialogFragment( fragmentAdapter.getFragmentList().get(pos), new Callable() { @Override public Object call() throws Exception { refreshActionBarColumns(); return null; } }); frag.show(getSupportFragmentManager(), "dialog"); hideOptionsColumns(); } }); // cargar el popup de enlaces FrameLayout root = ((FrameLayout) findViewById(R.id.tweettopics_root)); popupLinks = new PopupLinks(this); popupLinks.loadPopup(root); splitActionBarMenu = new SplitActionBarMenu(this); splitActionBarMenu.loadSplitActionBarMenu(root); layoutBackgroundApp = (RelativeLayout) findViewById(R.id.tweettopics_layout_background_app); layoutBackgroundBar = (RelativeLayout) findViewById(R.id.tweettopics_bar_background); horizontalScrollViewColumns = (HorizontalScrollView) findViewById(R.id.tweettopics_bar_horizontal_scroll); layoutBackgroundColumnsBarContainer = (LinearLayout) findViewById(R.id.tweettopics_bar_columns_container); layoutBackgroundColumnsBar = (LinearLayout) findViewById(R.id.tweettopics_bar_columns); // layoutBackgroundColumnsBar.setCols(4); // // layoutBackgroundColumnsBar.setOnRearrangeListener(new OnRearrangeListener() { // public void onRearrange(int oldIndex, int newIndex) { // reorganizeColumns(oldIndex, newIndex); // } // // @Override // public void onStartDrag(int x, int index) { // showOptionsColumns(x, index, true); // } // // @Override // public void onMoveDragged(int index) { // hideOptionsColumns(); // } // // }); // layoutBackgroundColumnsBar.setOnItemClickListener(new AdapterView.OnItemClickListener() { // @Override // public void onItemClick(AdapterView<?> arg0, View arg1, int position, long arg3) { // showActionBarIndicatorAndMovePager(position); // } // }); imgBarAvatar = (ImageView) findViewById(R.id.tweettopics_bar_avatar); imgBarAvatarBg = (ImageView) findViewById(R.id.tweettopics_bar_avatar_bg); imgBarCounter = (TextView) findViewById(R.id.tweettopics_bar_counter); imgNewStatus = (ImageView) findViewById(R.id.tweettopics_bar_new_status); imgNewStatus.setOnClickListener(new View.OnClickListener() { @Override public void onClick(View view) { newStatus(); } }); imgBarAvatarGestureDetector = new GestureDetector(this, new GestureDetector.SimpleOnGestureListener() { @Override public void onLongPress(MotionEvent e) { if (fragmentAdapter.instantiateItem(pager, pager.getCurrentItem()) instanceof BaseListFragment) { ((BaseListFragment) fragmentAdapter.instantiateItem(pager, pager.getCurrentItem())).goToTop(); } } @Override public boolean onDoubleTap(MotionEvent e) { if (fragmentAdapter.instantiateItem(pager, pager.getCurrentItem()) instanceof BaseListFragment) { ((BaseListFragment) fragmentAdapter.instantiateItem(pager, pager.getCurrentItem())).goToTop(); } return true; } @Override public boolean onSingleTapConfirmed(MotionEvent e) { animateDragged(); return true; } @Override public boolean onDown(MotionEvent e) { return true; } }); imgBarAvatarBg.setOnTouchListener(new View.OnTouchListener() { @Override public boolean onTouch(View view, MotionEvent motionEvent) { return imgBarAvatarGestureDetector.onTouchEvent(motionEvent); } }); refreshTheme(); reloadBarAvatar(); refreshActionBarColumns(); if (goToColumnType >= 0) { if ((goToColumnType == TweetTopicsUtils.COLUMN_TIMELINE || goToColumnType == TweetTopicsUtils.COLUMN_MENTIONS || goToColumnType == TweetTopicsUtils.COLUMN_DIRECT_MESSAGES) && goToColumnUser >= 0) { openUserColumn(goToColumnUser, goToColumnType); } if (goToColumnType == TweetTopicsUtils.COLUMN_SEARCH && goToColumnSearch > 0) { openSearchColumn(new Entity("search", goToColumnSearch)); } } else if (goToColumnType == TweetTopicsUtils.COLUMN_MY_ACTIVITY) { } else if (goToColumnPosition > 0) { goToColumn((int) goToColumnPosition, false, selectedTweetId); } else if (positionFromSensor >= 0) { goToColumn(positionFromSensor, false, selectedTweetId); } else { int col = fragmentAdapter.getPositionColumnActive(); if (col > 0) goToColumn(col, false, selectedTweetId); } // comprobar si hay que proponer ir al market int access_count = PreferenceUtils.getApplicationAccessCount(this); if (access_count <= 20) { if (access_count == 20) { try { AlertDialog dialog = DialogUtils.RateAppDialogBuilder.create(this); dialog.show(); } catch (PackageManager.NameNotFoundException e) { e.printStackTrace(); } } PreferenceUtils.setApplicationAccessCount(this, access_count + 1); } PreferenceUtils.showChangeLog(this, true); }
From source file:org.centum.android.MainActivity.java
/** * Report uncaught exceptions (crashes) to Analytics */// www. j ava 2 s . co m private void setupUncaughtExceptionHandler() { ExceptionReporter myHandler = new ExceptionReporter(EasyTracker.getInstance(this), GAServiceManager.getInstance(), Thread.getDefaultUncaughtExceptionHandler(), this); StandardExceptionParser exceptionParser = new StandardExceptionParser(getApplicationContext(), null) { @Override public String getDescription(String threadName, Throwable t) { return "{" + threadName + "} " + "{" + Build.MODEL + "} " + "{" + Build.VERSION.SDK_INT + "} " + Log.getStackTraceString(t); } }; myHandler.setExceptionParser(exceptionParser); Thread.setDefaultUncaughtExceptionHandler(myHandler); }
From source file:com.mparticle.internal.ConfigManager.java
public void enableUncaughtExceptionLogging(boolean userTriggered) { if (null == mExHandler) { Thread.UncaughtExceptionHandler currentUncaughtExceptionHandler = Thread .getDefaultUncaughtExceptionHandler(); if (!(currentUncaughtExceptionHandler instanceof ExceptionHandler)) { mExHandler = new ExceptionHandler(currentUncaughtExceptionHandler); Thread.setDefaultUncaughtExceptionHandler(mExHandler); if (userTriggered) { setLogUnhandledExceptions(true); }//w w w. j a va2 s. c om } } }
From source file:com.mparticle.internal.ConfigManager.java
public void disableUncaughtExceptionLogging(boolean userTriggered) { if (null != mExHandler) { Thread.UncaughtExceptionHandler currentUncaughtExceptionHandler = Thread .getDefaultUncaughtExceptionHandler(); if (currentUncaughtExceptionHandler instanceof ExceptionHandler) { Thread.setDefaultUncaughtExceptionHandler(mExHandler.getOriginalExceptionHandler()); mExHandler = null;/*from w ww . ja v a2s .c om*/ if (userTriggered) { setLogUnhandledExceptions(false); } } } }
From source file:com.dragoniade.deviantart.deviation.SearchStream.java
public List<Collection> getCollections() { List<Collection> collections = new ArrayList<Collection>(); if (search.getCollection() == null) { collections.add(null);//from w w w .j a v a 2 s.c om return collections; } String queryString = "http://" + user + ".deviantart.com/" + search.getCollection() + "/"; GetMethod method = new GetMethod(queryString); try { int sc = -1; do { sc = client.executeMethod(method); if (sc != 200) { LoggableException ex = new LoggableException(method.getResponseBodyAsString()); Thread.getDefaultUncaughtExceptionHandler().uncaughtException(Thread.currentThread(), ex); int res = DialogHelper.showConfirmDialog(owner, "An error has occured when contacting deviantART : error " + sc + ". Try again?", "Continue?", JOptionPane.YES_NO_OPTION); if (res == JOptionPane.NO_OPTION) { return null; } } } while (sc != 200); InputStream is = method.getResponseBodyAsStream(); ByteArrayOutputStream baos = new ByteArrayOutputStream(); byte[] buffer = new byte[4096]; int read = -1; while ((read = is.read(buffer)) > -1) { baos.write(buffer, 0, read); } String charsetName = method.getResponseCharSet(); String body = baos.toString(charsetName); String regex = user + ".deviantart.com/" + search.getCollection() + "/([0-9]+)\"[^>]*>([^<]+)<"; Pattern pattern = Pattern.compile(regex, Pattern.CASE_INSENSITIVE); Matcher matcher = pattern.matcher(body); while (matcher.find()) { String id = matcher.group(1); String name = matcher.group(2); Collection c = new Collection(Long.parseLong(id), name); collections.add(c); } } catch (IOException e) { } finally { method.releaseConnection(); } collections.add(null); return collections; }
From source file:org.acra.ErrorReporter.java
/** * Can only be constructed from within this class. * * @param context// ww w .j a v a 2 s. c o m * Context for the application in which ACRA is running. * @param prefs * SharedPreferences used by ACRA. * @param enabled * Whether this ErrorReporter should capture Exceptions and * forward their reports. */ ErrorReporter(Application context, SharedPreferences prefs, boolean enabled) { this.mContext = context; this.prefs = prefs; this.enabled = enabled; // Store the initial Configuration state. // This is expensive to gather, so only do so if we plan to report it. final String initialConfiguration; if (ACRA.getConfig().getReportFields().contains(ReportField.INITIAL_CONFIGURATION)) { initialConfiguration = ConfigurationCollector.collectConfiguration(mContext); } else { initialConfiguration = null; } // Sets the application start date. // This will be included in the reports, will be helpful compared to // user_crash date. final Calendar appStartDate = new GregorianCalendar(); if (Compatibility.getAPILevel() >= Compatibility.VERSION_CODES.ICE_CREAM_SANDWICH) { // ActivityLifecycleCallback // only available for API14+ ApplicationHelper.registerActivityLifecycleCallbacks(context, new ActivityLifecycleCallbacksCompat() { @Override public void onActivityCreated(Activity activity, Bundle savedInstanceState) { if (ACRA.DEV_LOGGING) ACRA.log.d(LOG_TAG, "onActivityCreated " + activity.getClass()); if (!(activity instanceof BaseCrashReportDialog)) { // Ignore CrashReportDialog because we want the last // application Activity that was started so that we can // explicitly kill it off. lastActivityCreated = new WeakReference<Activity>(activity); } } @Override public void onActivityStarted(Activity activity) { if (ACRA.DEV_LOGGING) ACRA.log.d(LOG_TAG, "onActivityStarted " + activity.getClass()); } @Override public void onActivityResumed(Activity activity) { if (ACRA.DEV_LOGGING) ACRA.log.d(LOG_TAG, "onActivityResumed " + activity.getClass()); } @Override public void onActivityPaused(Activity activity) { if (ACRA.DEV_LOGGING) ACRA.log.d(LOG_TAG, "onActivityPaused " + activity.getClass()); } @Override public void onActivityStopped(Activity activity) { if (ACRA.DEV_LOGGING) ACRA.log.d(LOG_TAG, "onActivityStopped " + activity.getClass()); } @Override public void onActivitySaveInstanceState(Activity activity, Bundle outState) { if (ACRA.DEV_LOGGING) ACRA.log.i(LOG_TAG, "onActivitySaveInstanceState " + activity.getClass()); } @Override public void onActivityDestroyed(Activity activity) { if (ACRA.DEV_LOGGING) ACRA.log.i(LOG_TAG, "onActivityDestroyed " + activity.getClass()); } }); } crashReportDataFactory = new CrashReportDataFactory(mContext, prefs, appStartDate, initialConfiguration); // If mDfltExceptionHandler is not null, initialization is already done. // Don't do it twice to avoid losing the original handler. mDfltExceptionHandler = Thread.getDefaultUncaughtExceptionHandler(); Thread.setDefaultUncaughtExceptionHandler(this); }
From source file:com.druk.bonjour.browser.ui.fragment.ServiceBrowserFragment.java
protected void showError(final Throwable e) { getActivity().runOnUiThread(() -> { mRecyclerView.animate().alpha(0.0f).setInterpolator(new AccelerateDecelerateInterpolator()) .setListener(new AnimatorListenerAdapter() { @Override/*www. j a v a2 s.c o m*/ public void onAnimationEnd(Animator animation) { mRecyclerView.setVisibility(View.GONE); } }).start(); mProgressView.animate().alpha(0.0f).setInterpolator(new AccelerateDecelerateInterpolator()) .setListener(new AnimatorListenerAdapter() { @Override public void onAnimationEnd(Animator animation) { mProgressView.setVisibility(View.GONE); } }).start(); mErrorView.setAlpha(0.0f); mErrorView.setVisibility(View.VISIBLE); mErrorView.animate().alpha(1.0f).setInterpolator(new AccelerateDecelerateInterpolator()).start(); mErrorView.findViewById(R.id.send_report).setOnClickListener( v -> Thread.getDefaultUncaughtExceptionHandler().uncaughtException(Thread.currentThread(), e)); }); }
From source file:com.druk.servicebrowser.ui.fragment.ServiceBrowserFragment.java
protected void showError(final Throwable e) { getActivity().runOnUiThread(new Runnable() { @Override/*from ww w. j a va 2 s.c o m*/ public void run() { mRecyclerView.animate().alpha(0.0f).setInterpolator(new AccelerateDecelerateInterpolator()) .setListener(new AnimatorListenerAdapter() { @Override public void onAnimationEnd(Animator animation) { mRecyclerView.setVisibility(View.GONE); } }).start(); mProgressView.animate().alpha(0.0f).setInterpolator(new AccelerateDecelerateInterpolator()) .setListener(new AnimatorListenerAdapter() { @Override public void onAnimationEnd(Animator animation) { mProgressView.setVisibility(View.GONE); } }).start(); mErrorView.setAlpha(0.0f); mErrorView.setVisibility(View.VISIBLE); mErrorView.animate().alpha(1.0f).setInterpolator(new AccelerateDecelerateInterpolator()).start(); mErrorView.findViewById(R.id.send_report).setOnClickListener(new View.OnClickListener() { @Override public void onClick(View v) { Thread.getDefaultUncaughtExceptionHandler().uncaughtException(Thread.currentThread(), e); } }); } }); }
From source file:org.transdroid.core.gui.TorrentsActivity.java
@Override public void onCreate(Bundle savedInstanceState) { // Set the theme according to the user preference if (SystemSettings_.getInstance_(this).useDarkTheme()) { setTheme(R.style.TransdroidTheme_Dark); }/*from ww w.ja va 2s . c o m*/ // Catch any uncaught exception to log it Thread.setDefaultUncaughtExceptionHandler( new LogUncaughtExceptionHandler(this, Thread.getDefaultUncaughtExceptionHandler())); super.onCreate(savedInstanceState); }