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:me.mast3rplan.phantombot.cache.ChannelUsersCache.java

@SuppressWarnings("CallToThreadStartDuringObjectConstruction")
private ChannelUsersCache(String channel) {
    if (channel.startsWith("#")) {
        channel = channel.substring(1);//from  w w  w . j  av  a2s.c om
    }

    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:me.mast3rplan.phantombot.script.Script.java

@SuppressWarnings("CallToThreadStartDuringObjectConstruction")
public Script(File file) {

    if (PhantomBot.reloadScripts) {
        this.fileWatcher = new ScriptFileWatcher(this);
    } else {//from w ww .ja v a 2  s.c o  m
        if (file.getPath().indexOf("/lang/") != -1) {
            this.fileWatcher = new ScriptFileWatcher(this);
        } else {
            this.fileWatcher = null;
        }
    }
    this.file = file;

    if (!file.getName().endsWith(".js") || file.getName().startsWith(".")) {
        return;
    }

    Thread.setDefaultUncaughtExceptionHandler(com.gmt2001.UncaughtExceptionHandler.instance());

    if (this.fileWatcher != null) {
        new Thread(fileWatcher).start();
    }
}

From source file:com.opentech.camel.task.BootstrapTest.java

@Before
public void before() {
    Thread.setDefaultUncaughtExceptionHandler(new UncaughtExceptionHandler() {

        @Override//from   w  w  w .  ja  v a 2s .  c  om
        public void uncaughtException(Thread t, Throwable e) {
            System.out.println(String.format("Exception Thread:%s", t.getName()));
            e.printStackTrace();
        }

    });
}

From source file:co.bugjar.android.monitor.BugjarMonitor.java

/**
 * Initialize the monitor to handle uncaught exceptions
 * //w  w w . j a v  a 2s  .  co  m
 * @param packageName the application package name
 * @param apiKey the account API key
 */
public static void initialize(Context context, String apiKey) {
    String packageName = context.getPackageName();

    String filesDir = Environment.getExternalStorageDirectory() + "/Android/data/" + packageName
            + STACK_TRACES_PATH;

    Log.d(TAG, "files dir is " + filesDir);
    try {
        PackageInfo info = context.getPackageManager().getPackageInfo(packageName, 0);
        BugjarMonitor m = new BugjarMonitor(filesDir, apiKey, info.versionName, info.versionCode);

        Thread.setDefaultUncaughtExceptionHandler(m.exceptionHandler());
        m.submitStackTraces(context);
    } catch (NameNotFoundException e) {
        Log.e(TAG, "couldn't determine version name or code while initializing: " + e.getMessage());
    }
}

From source file:org.jmpm.ethbadge.MainActivity.java

@Override
protected void onCreate(Bundle savedInstanceState) {
    Thread.setDefaultUncaughtExceptionHandler(handleAppCrash);
    super.onCreate(savedInstanceState);
    setContentView(R.layout.activity_main);

    try {//from   w  w  w. ja va  2  s .  co  m
        GlobalAppSettings.getInstance().initialize(getApplicationContext());

        BluetoothAdapter mBluetoothAdapter = BluetoothAdapter.getDefaultAdapter();
        if (!mBluetoothAdapter.isEnabled()) {
            Intent enableIntent = new Intent(BluetoothAdapter.ACTION_REQUEST_ENABLE);
            startActivityForResult(enableIntent, BluetoothConstants.REQUEST_ENABLE_BT);
        }

    } catch (Exception e) {
        Utils.sendFeedbackEmail(getApplicationContext(), (Exception) e);
        Toast.makeText(getApplicationContext(), GlobalAppConstants.UNEXPECTED_FATAL_EXCEPTION_MESSAGE,
                Toast.LENGTH_LONG).show();
    }

    try {
        final AppCompatActivity myself = this;
        if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.M) { // Only ask for these permissions on runtime when running Android 6.0 or higher
            switch (ContextCompat.checkSelfPermission(getBaseContext(),
                    Manifest.permission.ACCESS_COARSE_LOCATION)) {
            case PackageManager.PERMISSION_DENIED:
                ((TextView) new AlertDialog.Builder(this).setTitle("IMPORTANT").setMessage(Html.fromHtml(
                        "<p>This app requires Bluetooth permissions to work. In addition, some devices require access to device's location permissions to find nearby Bluetooth devices. Please click \"Allow\" on the following runtime permissions popup.</p>"
                                + "<p>For more info see <a href=\"http://developer.android.com/about/versions/marshmallow/android-6.0-changes.html#behavior-hardware-id\">here</a>.</p>"))
                        .setNeutralButton("Okay", new DialogInterface.OnClickListener() {
                            @Override
                            public void onClick(DialogInterface dialog, int which) {
                                if (ContextCompat.checkSelfPermission(getBaseContext(),
                                        Manifest.permission.ACCESS_COARSE_LOCATION) != PackageManager.PERMISSION_GRANTED) {
                                    int i = 5;
                                    ActivityCompat.requestPermissions(myself,
                                            new String[] { Manifest.permission.ACCESS_COARSE_LOCATION }, 1);
                                }
                            }
                        }).show().findViewById(android.R.id.message))
                                .setMovementMethod(LinkMovementMethod.getInstance()); // Make the link clickable. Needs to be called after show(), in order to generate hyperlinks
                break;
            case PackageManager.PERMISSION_GRANTED:
                break;
            }
        }
    } catch (Exception e) {
        Utils.sendFeedbackEmail(getApplicationContext(), (Exception) e);
        Toast.makeText(getApplicationContext(), "Error: Could not set permissions", Toast.LENGTH_LONG).show();
    }
}

From source file:alfio.config.Initializer.java

@Override
public void onStartup(ServletContext servletContext) throws ServletException {
    super.onStartup(servletContext);

    Thread.setDefaultUncaughtExceptionHandler(new DefaultExceptionHandler());

    configureSessionCookie(servletContext);

    CharacterEncodingFilter cef = new CharacterEncodingFilter();
    cef.setEncoding("UTF-8");
    cef.setForceEncoding(true);//from   www . ja va2 s  .com

    Dynamic characterEncodingFilter = servletContext.addFilter("CharacterEncodingFilter", cef);
    characterEncodingFilter.setAsyncSupported(true);
    characterEncodingFilter.addMappingForUrlPatterns(null, false, "/*");

    //force log initialization, then disable it
    XRLog.setLevel(XRLog.EXCEPTION, Level.WARNING);
    XRLog.setLoggingEnabled(false);

}

From source file:com.gmt2001.IniStore.java

private IniStore() {
    inifolder = LoadConfigReal("");

    t = new Timer((int) saveInterval, this);
    t2 = new Timer(1, this);

    Thread.setDefaultUncaughtExceptionHandler(com.gmt2001.UncaughtExceptionHandler.instance());

    t.start();//from ww w. j a  v  a 2  s.c o  m
}

From source file:me.gloriouseggroll.quorrabot.script.ScriptEventManager.java

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

From source file:com.gmt2001.datastore.IniStore.java

private IniStore() {
    inifolder = LoadConfigReal("");

    t = new Timer((int) saveinterval, this);
    t2 = new Timer(1, this);

    Thread.setDefaultUncaughtExceptionHandler(com.gmt2001.UncaughtExceptionHandler.instance());

    t.start();//from  w  w  w.j  a va  2 s . c  om
}

From source file:com.spotify.helios.system.AgentStateDirConflictTest.java

@After
public void teardown() throws Exception {
    FileUtils.deleteQuietly(stateDir.toFile());
    stopQuietly(first);/* w  w w . j  a  va2 s .c  om*/
    stopQuietly(second);
    Thread.setDefaultUncaughtExceptionHandler(dueh);
    zk.stop();
}