Example usage for java.lang Thread setDefaultUncaughtExceptionHandler

List of usage examples for java.lang Thread setDefaultUncaughtExceptionHandler

Introduction

In this page you can find the example usage for java.lang Thread setDefaultUncaughtExceptionHandler.

Prototype

public static void setDefaultUncaughtExceptionHandler(UncaughtExceptionHandler eh) 

Source Link

Document

Set the default handler invoked when a thread abruptly terminates due to an uncaught exception, and no other handler has been defined for that thread.

Usage

From source file:com.mgmtp.perfload.loadprofiles.ui.AppFrame.java

/**
 * Launch the application./* w  ww . ja  v a 2s . co m*/
 */
public static void main(final String[] args) {
    File baseDir = new File(System.getProperty("basedir", "."));

    final Injector inj = Guice.createInjector(new AppModule(baseDir));
    final ConfigController configCtrl = inj.getInstance(ConfigController.class);

    try {
        UIManager.setLookAndFeel(configCtrl.getLookAndFeelClassName());
    } catch (Exception ex) {
        LOG.error(ex.getMessage(), ex);
    }

    ExceptionHandler exceptionHandler = inj.getInstance(ExceptionHandler.class);
    Thread.setDefaultUncaughtExceptionHandler(exceptionHandler);

    // This is necessary because an UncaughtExceptionHandler does not work in modal dialogs
    System.setProperty("sun.awt.exception.handler", ExceptionHandler.class.getName());

    EventQueue.invokeLater(new Runnable() {
        @Override
        public void run() {
            try {
                AppFrame frame = inj.getInstance(AppFrame.class);

                Rectangle bounds = configCtrl.getFrameBounds();
                if (bounds != null) {
                    frame.setBounds(bounds);
                }
                ImageIcon icon = new ImageIcon(
                        getResource("com/mgmtp/perfload/loadprofiles/ui/perfLoad_Logo_bild_64x64.png"));
                frame.setIconImage(icon.getImage());
                frame.updateLists();
                frame.updateGraph();
                frame.addTableListeners();
                frame.setUpEventBus();
                frame.setExtendedState(configCtrl.getFrameState());
                frame.setVisible(true);
            } catch (Exception ex) {
                ex.printStackTrace();
            }
        }
    });
}

From source file:com.gmt2001.TwitchAPIv5.java

private TwitchAPIv5() {
    Thread.setDefaultUncaughtExceptionHandler(com.gmt2001.UncaughtExceptionHandler.instance());
}

From source file:com.microsoft.onenote.pickerlib.OneNotePickerActivity.java

@Override
protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);

    // Handle uncaught and system exceptions
    Thread.setDefaultUncaughtExceptionHandler(new Thread.UncaughtExceptionHandler() {
        @Override/*w  w w .  jav  a 2 s .  c  o m*/
        public void uncaughtException(Thread thread, Throwable throwable) {
            handleError(throwable);
        }
    });

    // Use the slide in animation
    overridePendingTransition(R.anim.slide_in, R.anim.hold);

    readExtras();

    // Determine the theme to use
    if (mThemeColor == null || mThemeColor == OneNotePickerThemeColor.LIGHT) {
        setTheme(R.style.OneNotePicker_Light);
    } else if (mThemeColor == OneNotePickerThemeColor.DARK) {
        setTheme(R.style.OneNotePicker_Dark);
    }

    setUpActionBar();

    setContentView(R.layout.activity_onenote_picker);

    // Retrieve the controller fragment
    FragmentManager fm = getSupportFragmentManager();
    mControllerFragment = (ControllerFragment) fm.findFragmentByTag("controller");

    if (savedInstanceState == null) {
        mNotebooksFragment = new PickerListFragment(new UiActionBarSettings(getString(R.string.text_notebooks),
                getString(R.string.text_onenote), false));

        mNotebooksFragment.mLoading = true;

        // Create the controller fragment the first time
        if (mControllerFragment == null) {
            mControllerFragment = new ControllerFragment(mAccessToken, mNotebooksFragment);
            fm.beginTransaction().add(mControllerFragment, "controller").commit();
        }

        // Show the first fragment
        addFragment(mNotebooksFragment);
    }

}

From source file:com.google.reviewit.app.ReviewItApp.java

@Override
public void onCreate() {
    registerActivityLifecycleCallbacks(new ActivityLifecycleCallbacks() {
        @Override/*from  w  ww. j  av  a 2  s . c o  m*/
        public void onActivityCreated(Activity activity, Bundle savedInstanceState) {
            currentActivity = (FragmentActivity) activity;
        }

        @Override
        public void onActivityStarted(Activity activity) {
        }

        @Override
        public void onActivityResumed(Activity activity) {
        }

        @Override
        public void onActivityPaused(Activity activity) {
        }

        @Override
        public void onActivityStopped(Activity activity) {
        }

        @Override
        public void onActivitySaveInstanceState(Activity activity, Bundle outState) {
        }

        @Override
        public void onActivityDestroyed(Activity activity) {
            currentActivity = null;
        }
    });

    Thread.setDefaultUncaughtExceptionHandler(new Thread.UncaughtExceptionHandler() {
        @Override
        public void uncaughtException(Thread thread, Throwable t) {
            Log.e(TAG, "Application failure", t);
            if (currentActivity != null) {
                FragmentManager fragmentManager = currentActivity.getSupportFragmentManager();
                fragmentManager.beginTransaction().replace(R.id.mainFrame, ErrorFragment.create(t)).commit();
            }
        }
    });
    super.onCreate();
}

From source file:me.mast3rplan.phantombot.cache.SubscribersCache.java

@SuppressWarnings("CallToThreadStartDuringObjectConstruction")
private SubscribersCache(String channel) {
    if (channel.startsWith("#")) {
        channel = channel.substring(1);//from  www  .jav  a2s  .co m
    }

    this.channel = channel;
    this.updateThread = new Thread(this);
    this.cache = Maps.newHashMap();

    Thread.setDefaultUncaughtExceptionHandler(com.gmt2001.UncaughtExceptionHandler.instance());
    this.updateThread.setUncaughtExceptionHandler(com.gmt2001.UncaughtExceptionHandler.instance());

    updateThread.start();
}

From source file:com.moto.miletus.application.DeviceActivity.java

@Override
protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);

    setContentView(R.layout.activity_device);

    if (!(Thread.getDefaultUncaughtExceptionHandler() instanceof CustomExceptionHandler)) {
        Thread.setDefaultUncaughtExceptionHandler(new CustomExceptionHandler(this));
    }/*from  w w w  .  j a v  a 2  s  .c  om*/

    getWindow().addFlags(WindowManager.LayoutParams.FLAG_KEEP_SCREEN_ON);
    setRequestedOrientation(ActivityInfo.SCREEN_ORIENTATION_LOCKED);

    final Bundle state = savedInstanceState != null ? savedInstanceState : getIntent().getExtras();
    mDevice = state.getParcelable(Strings.EXTRA_KEY_DEVICE);
    if (mDevice == null) {
        throw new IllegalArgumentException("No Device set in intent extra " + Strings.EXTRA_KEY_DEVICE);
    }

    final ActionBar actionBar = getSupportActionBar();
    if (actionBar == null) {
        return;
    }

    actionBar.setNavigationMode(ActionBar.NAVIGATION_MODE_TABS);
    actionBar.setDisplayHomeAsUpEnabled(true);
    actionBar.setDisplayShowHomeEnabled(true);
    actionBar.setTitle(R.string.app_name);
    //actionBar.setSubtitle(mDevice.getName());

    SectionsPagerAdapter mSectionsPagerAdapter = new SectionsPagerAdapter(getSupportFragmentManager());

    mViewPager = (ViewPager) findViewById(R.id.container);
    if (mViewPager != null) {
        mViewPager.setAdapter(mSectionsPagerAdapter);
        mViewPager.setOnPageChangeListener(new ViewPager.SimpleOnPageChangeListener() {
            @Override
            public void onPageSelected(int position) {
                actionBar.setSelectedNavigationItem(position);
            }
        });
    }

    for (int i = 0; i < mSectionsPagerAdapter.getCount(); i++) {
        actionBar
                .addTab(actionBar.newTab().setText(mSectionsPagerAdapter.getPageTitle(i)).setTabListener(this));
    }
}

From source file:io.github.carlorodriguez.alarmon.AlarmClockService.java

@Override
public void onCreate() {
    super.onCreate();
    // Registers an exception handler of capable of writing the stack trace
    // to the device's SD card.  This is only possible if the proper
    // permissions are available.
    if (getPackageManager().checkPermission("android.permission.WRITE_EXTERNAL_STORAGE",
            getPackageName()) == PackageManager.PERMISSION_GRANTED) {
        Thread.setDefaultUncaughtExceptionHandler(
                new LoggingUncaughtExceptionHandler(Environment.getExternalStorageDirectory().getPath()));
    }/*w  w  w. ja  v a  2s. c o  m*/

    // Access to in-memory and persistent data structures.
    db = new DbAccessor(getApplicationContext());
    pendingAlarms = new PendingAlarmList(getApplicationContext());

    // Schedule enabled alarms during initial startup.
    for (Long alarmId : db.getEnabledAlarms()) {
        if (pendingAlarms.pendingTime(alarmId) != null) {
            continue;
        }
        if (AppSettings.isDebugMode(getApplicationContext())) {
            Toast.makeText(getApplicationContext(), "RENABLE " + alarmId, Toast.LENGTH_SHORT).show();
        }

        AlarmTime alarmTime = null;

        AlarmInfo info = db.readAlarmInfo(alarmId);

        if (info != null) {
            alarmTime = info.getTime();
        }

        pendingAlarms.put(alarmId, alarmTime);
    }

    ReceiverNotificationRefresh.startRefreshing(getApplicationContext());
}

From source file:com.moto.miletus.application.utils.MqttSettingsActivity.java

@Override
protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.activity_mqtt);

    if (!(Thread.getDefaultUncaughtExceptionHandler() instanceof CustomExceptionHandler)) {
        Thread.setDefaultUncaughtExceptionHandler(new CustomExceptionHandler(this));
    }/*from ww  w  . jav a 2s.c o m*/

    getWindow().addFlags(WindowManager.LayoutParams.FLAG_KEEP_SCREEN_ON);
    setRequestedOrientation(ActivityInfo.SCREEN_ORIENTATION_LOCKED);

    final Button saveSettings = (Button) findViewById(R.id.save_settings);

    if (saveSettings != null) {
        saveSettings.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View view) {
                saveSettings();
                testConnect();
            }
        });
    }

    initialize();
}

From source file:me.mast3rplan.phantombot.cache.FollowersCache.java

@SuppressWarnings("CallToThreadStartDuringObjectConstruction")
private FollowersCache(String channel) {
    if (channel.startsWith("#")) {
        channel = channel.substring(1);/*  w w w.  ja v  a2 s  .com*/
    }

    this.channel = channel;
    this.updateThread = new Thread(this);

    Thread.setDefaultUncaughtExceptionHandler(com.gmt2001.UncaughtExceptionHandler.instance());
    this.updateThread.setUncaughtExceptionHandler(com.gmt2001.UncaughtExceptionHandler.instance());

    updateThread.start();
}

From source file:own.projects.lemiroapp.GameModeActivity.java

private void setDefaultUncaughtExceptionHandler() {
    try {/*from   ww w .j a v  a2s. c  o m*/
        Thread.setDefaultUncaughtExceptionHandler(new Thread.UncaughtExceptionHandler() {

            @Override
            public void uncaughtException(Thread t, Throwable e) {
                StackTraceElement[] trace = e.getStackTrace();
                String tracem = "";
                for (int i = 0; i < trace.length; i++) {
                    tracem += trace[i] + "\n";
                }
                Log.e("GameModeActivity", "Uncaught Exception detected in thread {}" + t + e + "\n" + tracem);

                final String message = e.getMessage();

                //display message so that the user sees that something went wrong
                runOnUiThread(new Runnable() {
                    @Override
                    public void run() {
                        new AlertDialog.Builder(THIS).setIcon(android.R.drawable.ic_dialog_info)
                                .setTitle("Error").setMessage(message).setCancelable(false)
                                .setNeutralButton("Quit", new DialogInterface.OnClickListener() {
                                    public void onClick(DialogInterface dialog, int id) {
                                        finish();
                                    }
                                }).show();
                    }
                });

            }
        });
    } catch (SecurityException e) {
        Log.e("GameModeActivity", "Could not set the Default Uncaught Exception Handler" + e);
    }
}