Example usage for java.lang Thread getDefaultUncaughtExceptionHandler

List of usage examples for java.lang Thread getDefaultUncaughtExceptionHandler

Introduction

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

Prototype

public static UncaughtExceptionHandler getDefaultUncaughtExceptionHandler() 

Source Link

Document

Returns the default handler invoked when a thread abruptly terminates due to an uncaught exception.

Usage

From source file:com.nullwire.ExceptionHandler.java

/**
 * Register handler for unhandled exceptions.
 * @param context//w  ww  .  jav 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   www.java2s  .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 ww .  ja  va2 s  .co 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:com.jwork.spycamera.SpyCamActivity.java

@Override
public void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    int v = 0;//from   w ww  .  jav a  2 s.c om
    try {
        v = this.getPackageManager().getPackageInfo(this.getPackageName(), 0).versionCode;
    } catch (NameNotFoundException e) {
    }
    log.v(this, "onCreate(): " + this.getString(R.string.app_versionName) + "(" + v + ")");
    Utility.setGlobalContext(this);

    defaultUEH = Thread.getDefaultUncaughtExceptionHandler();
    crashHandler = CrashHandler.getInstance(this, defaultUEH);
    Thread.setDefaultUncaughtExceptionHandler(crashHandler);
    setContentView(R.layout.activity_main);
    fragment = (MainFragment) getSupportFragmentManager().findFragmentById(R.id.fragmentMain);

    getDefaultOrientation();
    String action = getIntent().getAction();

    log.d(this, "action:" + action);
    if (action == null || action.equals("android.intent.action.MAIN") || action.equals(ACTION_WIDGET[0])) {
        fragment.setVisible();
    } else {
        for (int i = 1; i < ACTION_WIDGET.length; i++) {
            if (action.equals(ACTION_WIDGET[i])) {
                if (ConfigurationUtility.getInstance(this).isDisableBackgroundService()) {
                    fragment.setVisible();
                } else {
                    fragment.setVisibleForWidget();
                }
                fragment.callWidgetAction(i);
                return;
            }
        }
        fragment.setVisible();
    }
}

From source file:fi.iki.dezgeg.matkakorttiwidget.gui.MatkakorttiWidgetApp.java

@Override
public void onCreate() {
    super.onCreate();
    prefs = PreferenceManager.getDefaultSharedPreferences(getApplicationContext());
    try {/*from w  w w  .j a va  2  s.  c  o m*/
        packageInfo = getPackageManager().getPackageInfo(getPackageName(), 0);
    } catch (PackageManager.NameNotFoundException e) {
        e.printStackTrace();
    }

    prevUncaughtExceptionHandler = Thread.getDefaultUncaughtExceptionHandler();
    Thread.setDefaultUncaughtExceptionHandler(new Thread.UncaughtExceptionHandler() {
        @Override
        public void uncaughtException(Thread thread, Throwable e) {
            try {
                reportException("UncaughtExceptionHandler", e).get(8, TimeUnit.SECONDS);
            } catch (Throwable t) {
                // ignore
            }

            if (prevUncaughtExceptionHandler != null)
                prevUncaughtExceptionHandler.uncaughtException(thread, e);
        }
    });
}

From source file:com.jeffthefate.stacktrace.ExceptionHandler.java

/**
 * Register handler for unhandled exceptions.
 * @param context//from w  w  w .ja v a2s  . co m
 */
public static boolean register(Application app) {
    mCallback = (OnStacktraceListener) app;
    Log.i(TAG, "Registering default exceptions handler");
    // Get information about the Package
    PackageManager pm = app.getPackageManager();
    try {
        PackageInfo pi;
        // Version
        pi = pm.getPackageInfo(app.getPackageName(), 0);
        G.APP_VERSION = pi.versionName;
        // Package name
        G.APP_PACKAGE = pi.packageName;
        // Files dir for storing the stack traces
        G.FILES_PATH = app.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, "APP_VERSION: " + G.APP_VERSION);
    Log.d(TAG, "APP_PACKAGE: " + G.APP_PACKAGE);
    Log.d(TAG, "FILES_PATH: " + G.FILES_PATH);

    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.urremote.classifier.common.ExceptionHandler.java

protected ExceptionHandler(Context context, String appname, String url, String version, String imei) {
    this.context = context;
    this.appname = appname;
    this.url = url;
    this.version = version;
    this.imei = imei;
    this.defaultUEH = Thread.getDefaultUncaughtExceptionHandler();
}

From source file:uk.ac.horizon.ug.exploding.client.logging.LoggingUtils.java

/** init */
public static synchronized void init(Context context) {
    String packageName = context.getApplicationInfo().packageName;
    if (applicationDirName != null) {
        if (applicationDirName.equals(packageName))
            // no-op
            return;
        // close and re-initialise?
        Log.w(TAG, "Re-initialise logging with different package name: " + packageName + " vs "
                + applicationDirName);/*from   w w  w  .j a  va  2  s . co  m*/
        // TODO Log
        return;
    }
    applicationDirName = packageName;
    String fileName = "log_" + System.currentTimeMillis() + ".json";
    File dir = new File(LOG_ROOT_DIR, applicationDirName);
    if (dir.mkdir())
        Log.i(TAG, "Created log directory " + dir);
    if (!dir.exists()) {
        Log.e(TAG, "Log directory does not exist: " + dir + " - cannot log");
        return;
    }
    if (!dir.isDirectory()) {
        Log.e(TAG, "Log directory is not a directory: " + dir + " - cannot log");
        return;
    }
    File file = new File(LOG_ROOT_DIR + applicationDirName, fileName);
    if (file.exists())
        Log.w(TAG, "Appending to existing log: " + file);
    try {
        logWriter = new BufferedWriter(
                new OutputStreamWriter(new FileOutputStream(file, true), Charset.forName("UTF-8")));
        Log.i(TAG, "Logging to " + file);
        logFile = file;
    } catch (Exception e) {
        Log.e(TAG, "Opening log file " + file + " - cannot log", e);
        logWriter = null;
    }
    logHeader(context);

    // dump exceptions!
    final UncaughtExceptionHandler handler = Thread.getDefaultUncaughtExceptionHandler();
    Thread.setDefaultUncaughtExceptionHandler(new UncaughtExceptionHandler() {

        @Override
        public void uncaughtException(Thread thread, Throwable ex) {
            // TODO Auto-generated method stub
            try {
                JSONStringer js = new JSONStringer();
                js.object();
                js.key("thread");
                js.value(thread.getName());
                js.key("exception");
                js.value(ex.toString());
                js.key("stackTrace");
                StringWriter sw = new StringWriter();
                PrintWriter pw = new PrintWriter(sw);
                ex.printStackTrace(pw);
                js.value(sw.getBuffer().toString());
                js.endObject();
                log(LOGTYPE_UNCAUGHT_EXCEPTION, js.toString());
            } catch (Exception e) {
                Log.e(TAG, "Logging uncaught exception", e);
            }
            // cascade
            if (handler != null)
                handler.uncaughtException(thread, ex);
        }
    });
}

From source file:com.netdoers.zname.errorreporting.ExceptionHandler.java

/**
 * Register handler for unhandled exceptions.
 * @param context//  www  . j av  a 2 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;
        // Version Code name
        G.APP_VERSION_CODE = String.valueOf(pi.versionCode);//ADDED VERSION CODE
        // 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;
        // Device Size
        G.PHONE_SIZE = Zname.getPreferences().getDeviceSize();
        // 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_VERSION_CODE: " + G.APP_VERSION_CODE);//ADDED VERSION CODE
    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.netdoers.com.stacktrace.ExceptionHandler.java

/**
 * Register handler for unhandled exceptions.
 * @param context/*from  w  w w .  j a v  a2s.  co  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;
        // Version Code name
        G.APP_VERSION_CODE = String.valueOf(pi.versionCode);//ADDED VERSION CODE
        // 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;
        // Device Size
        G.PHONE_SIZE = SmartConsultant.getPreferences().getDeviceSize();
        // 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_VERSION_CODE: " + G.APP_VERSION_CODE);//ADDED VERSION CODE
    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;
}