List of usage examples for java.lang Thread setDefaultUncaughtExceptionHandler
public static void setDefaultUncaughtExceptionHandler(UncaughtExceptionHandler eh)
From source file:be.neutrinet.ispng.VPN.java
@Override public void init(DaemonContext dc) throws Exception { Logger root = Logger.getRootLogger(); root.setLevel(Level.INFO);//from w w w . j av a 2 s .c om root.addAppender(new ConsoleAppender(LAYOUT)); cfg = new Properties(); cfg.load(new FileInputStream("config.properties")); root.addAppender( new DailyRollingFileAppender(LAYOUT, cfg.getProperty("log.file", "ispng.log"), "'.'yyyy-MM-dd")); Thread.setDefaultUncaughtExceptionHandler(new Thread.UncaughtExceptionHandler() { @Override public void uncaughtException(Thread t, Throwable e) { Logger.getLogger(getClass()).error("Unhandled exception", e); } }); Zookeeper.boot(cfg.getProperty("zookeeper.connectionString")); Config.get().boot(); generator = new Generator(); Config.get().getAndWatch("log/level", "INFO", level -> root.setLevel(Level.toLevel(level))); Optional<String> dbUser = Config.get("db/user"); if (!dbUser.isPresent()) { cs = new JdbcConnectionSource(Config.get("db/uri").get()); } else { if (cfg.get("db.uri").toString().contains("mariadb")) { cs = new JdbcConnectionSource(cfg.getProperty("db.uri"), cfg.getProperty("db.user"), cfg.getProperty("db.password"), new MariaDBType()); } else if (cfg.get("db.uri").toString().contains("mysql")) { cs = new JdbcConnectionSource(cfg.getProperty("db.uri"), cfg.getProperty("db.user"), cfg.getProperty("db.password"), new MySQLDBType()); } else { cs = new JdbcConnectionSource(cfg.getProperty("db.uri"), cfg.getProperty("db.user"), cfg.getProperty("db.password")); } } }
From source file:org.imdea.panel.MainActivity.java
protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); Thread.setDefaultUncaughtExceptionHandler(new Thread.UncaughtExceptionHandler() { @Override/* w ww . j a v a 2 s . co m*/ public void uncaughtException(Thread paramThread, Throwable paramThrowable) { Log.e("Alert", "UNCAUGHT EXCEPTION", paramThrowable); System.exit(1); } }); Thread.setDefaultUncaughtExceptionHandler(onRuntimeError); /* ParseObject testObject = new ParseObject("TestObject"); testObject.put("foo", "bar"); testObject.saveInBackground();*/ SP = PreferenceManager.getDefaultSharedPreferences(this); //Abrimos la base de datos 'DBUsuarios' en modo escritura DBHelper msg_database = new DBHelper(this, "messages.db", null, 1); Global.db = msg_database.getWritableDatabase(); enableBt(); Intent intent = getIntent(); String action = intent.getAction(); String type = intent.getType(); setContentView(R.layout.activity_main); // Initilization viewPager = (ViewPager) findViewById(R.id.pager); actionbar = getActionBar(); try { ViewConfiguration config = ViewConfiguration.get(this); Field menuKeyField = ViewConfiguration.class.getDeclaredField("sHasPermanentMenuKey"); if (menuKeyField != null) { menuKeyField.setAccessible(true); menuKeyField.setBoolean(config, false); } } catch (Exception ex) { // Ignore } checkUsername(); TabsPagerAdapter mAdapter = new TabsPagerAdapter(getSupportFragmentManager()); fm = getSupportFragmentManager(); viewPager.setAdapter(mAdapter); actionbar.setNavigationMode(ActionBar.NAVIGATION_MODE_TABS); actionbar.addTab(actionbar.newTab().setText("General").setTabListener(this)); actionbar.addTab(actionbar.newTab().setText("Tags").setTabListener(this)); /** * on swiping the viewpager make respective tab selected * */ viewPager.setOnPageChangeListener(new ViewPager.OnPageChangeListener() { public void onPageSelected(int position) { // on changing the page // make respected tab selected actionbar.setSelectedNavigationItem(position); } public void onPageScrolled(int arg0, float arg1, int arg2) { } public void onPageScrollStateChanged(int arg0) { } }); /* EXPERIMENTAL SERVICES */ //this.startService(new Intent(this, WifiService.class)); //this.startService(new Intent(this, BtWizService.class)); //this.startService(new Intent(this, MeshService.class)); this.startService(new Intent(this, commService.class)); //if (Global.mqtt) this.startService(new Intent(this, mqttService.class)); //else this.startService(new Intent(this, BtService.class)); //this.startService(new Intent(this, smoothService.class)); if (Intent.ACTION_SEND.equals(action) && type != null) { if ("text/plain".equals(type)) { handleSendText(intent); // Handle text being sent } else if (type.startsWith("image/")) { handleSendImage(intent); // Handle single image being sent } } }
From source file:com.yojiokisoft.yumekanow.activity.MainActivity.java
/** * ?? (onCreate?????// w ww .j a v a 2 s. c o m */ @AfterViews /*package*/void initActivity() { // ????????? Thread.setDefaultUncaughtExceptionHandler(new MyUncaughtExceptionHandler()); SettingDao settingDao = SettingDao.getInstance(); // px -> dp ? if (!settingDao.getConvDpFlag()) { convPx2Dp(); settingDao.setConvDpFlag(true); } if (MyAlarmManager.getStartTime() == 0 && MyAlarmManager.getWakeUpTime() == 0) { MyAlarmManager.setStartTimer(this); } FragmentManager manager = getSupportFragmentManager(); mTabHost.setup(); final MainPagerAdapter adapter = new MainPagerAdapter(manager, this, mTabHost, mPager); // tab size from screen size DisplayMetrics metrics = new DisplayMetrics(); getWindowManager().getDefaultDisplay().getMetrics(metrics); int tabWidth = metrics.widthPixels / 3; int tabHeight = metrics.widthPixels / 7; String tabTitle[] = new String[3]; tabTitle[0] = getString(R.string.tab_title1); tabTitle[1] = getString(R.string.tab_title2); tabTitle[2] = getString(R.string.tab_title3); for (int i = 0; i < tabTitle.length; i++) { TabSpec spec = mTabHost.newTabSpec("tab" + i); spec.setIndicator(getTabView(tabWidth, tabHeight, tabTitle[i])); adapter.addTab(spec, "tab" + i); } if ("Timer".equals(mFireEvent)) { if (settingDao.getVibrator()) { mVibrator = (Vibrator) getSystemService(VIBRATOR_SERVICE); long[] pattern = { 0, 500, 250, 500, 250, 500 }; // OFF/ON/OFF/ON... mVibrator.vibrate(pattern, -1); } String url = settingDao.getAlarmUrl(); if (url != null) { mRingtone = RingtoneManager.getRingtone(this, Uri.parse(url)); mRingtone.play(); } } mCloseByButtonClicked = false; }
From source file:com.nullwire.ExceptionHandler.java
/** * Register handler for unhandled exceptions. * @param context/*from ww w. ja v a 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; // 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; // Android version G.ANDROID_VERSION = android.os.Build.VERSION.RELEASE; } catch (NameNotFoundException e) { e.printStackTrace(); } Log.d(TAG, "TRACE_VERSION: " + G.TraceVersion); Log.d(TAG, "APP_VERSION: " + G.APP_VERSION); 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:demo.vicshady.classes.ErrReport.ExceptionHandler.java
/** * Register handler for unhandled exceptions. * @param context/*from ww w .j a va2 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; // 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; // 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_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.l.notel.notel.org.redpin.android.util.ExceptionReporter.java
/** * Register handler for unhandled exceptions. * /* w w w . j a v a 2 s .c o m*/ * @param context */ 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); E.APP_VERSION = pi.versionName; // Package name E.APP_PACKAGE = pi.packageName; // Files dir for storing the stack traces E.FILES_PATH = context.getFilesDir().getAbsolutePath(); // Device model E.PHONE_MODEL = android.os.Build.MODEL; // Android version E.ANDROID_VERSION = android.os.Build.VERSION.RELEASE; } catch (NameNotFoundException e) { e.printStackTrace(); } Log.i(TAG, "TRACE_VERSION: " + E.TraceVersion); Log.d(TAG, "APP_VERSION: " + E.APP_VERSION); Log.d(TAG, "APP_PACKAGE: " + E.APP_PACKAGE); Log.d(TAG, "FILES_PATH: " + E.FILES_PATH); Log.d(TAG, "URL: " + E.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 ExceptionHandler)) { // Register default exceptions handler Thread.setDefaultUncaughtExceptionHandler(new ExceptionHandler(currentHandler)); } } }.start(); return stackTracesFound; }
From source file:se.idsecurity.ldifcompare.LdifUtilities.java
/** * Creates a new instance of this tool.//from ww w . j ava 2s . co m * * @param outStream The output stream to which standard out should be * written. It may be {@code null} if output should be * suppressed. * @param errStream The output stream to which standard error should be * written. It may be {@code null} if error messages * should be suppressed. */ public LdifUtilities(OutputStream outStream, OutputStream errStream) { super(outStream, errStream); Thread.setDefaultUncaughtExceptionHandler(new UncaughtExceptionHandler()); }
From source file:org.spoutcraft.launcher.entrypoint.SpoutcraftLauncher.java
protected static Logger setupLogger() { final Logger logger = Utils.getLogger(); File logDirectory = new File(Utils.getLauncherDirectory(), "logs"); if (!logDirectory.exists()) { logDirectory.mkdir();//from w ww .ja v a 2 s. c o m } File logs = new File(logDirectory, "techniclauncher_%D.log"); RotatingFileHandler fileHandler = new RotatingFileHandler(logs.getPath()); fileHandler.setFormatter(new TechnicLogFormatter()); for (Handler h : logger.getHandlers()) { logger.removeHandler(h); } logger.addHandler(fileHandler); SpoutcraftLauncher.handler = fileHandler; if (params != null && !params.isDebugMode()) { logger.setUseParentHandlers(false); System.setOut(new PrintStream(new LoggerOutputStream(console, Level.INFO, logger), true)); System.setErr(new PrintStream(new LoggerOutputStream(console, Level.SEVERE, logger), true)); } Thread.setDefaultUncaughtExceptionHandler(new Thread.UncaughtExceptionHandler() { @Override public void uncaughtException(Thread t, Throwable e) { logger.log(Level.SEVERE, "Unhandled Exception in " + t, e); if (errorDialog == null) { LauncherFrame frame = null; try { frame = Launcher.getFrame(); } catch (Exception ex) { //This can happen if we have a very early crash- before Launcher initializes } errorDialog = new ErrorDialog(frame, e); errorDialog.setVisible(true); } } }); return logger; }
From source file:com.idisplay.base.IDisplayApp.java
public void onCreate() { super.onCreate(); Logger.initLogger(this); Logger.i("---------------------------------\nStarting iDisplay app, v" + Utils.getApplicationVersion()); dumpMainLooper("onCreate"); Thread.setDefaultUncaughtExceptionHandler(new TopExceptionHandler(this)); }
From source file:cx.ring.client.HomeActivity.java
private static void setDefaultUncaughtExceptionHandler() { try {/*from w w w . jav a2s. c om*/ Thread.setDefaultUncaughtExceptionHandler(new Thread.UncaughtExceptionHandler() { @Override public void uncaughtException(Thread t, Throwable e) { Log.e(TAG, "Uncaught Exception detected in thread ", e); //e.printStackTrace(); } }); } catch (SecurityException e) { Log.e(TAG, "Could not set the Default Uncaught Exception Handler"); } }