コード例 #1
0
 @Override
 public final void run() {
   try {
     _r.run();
   } catch (final Throwable e) {
     final Thread t = Thread.currentThread();
     final UncaughtExceptionHandler h = t.getUncaughtExceptionHandler();
     if (h != null) h.uncaughtException(t, e);
   }
 }
コード例 #2
0
ファイル: VlcCrashHandler.java プロジェクト: JokeLook/YiYuan
  @Override
  public void uncaughtException(Thread thread, Throwable ex) {

    final Writer result = new StringWriter();
    final PrintWriter printWriter = new PrintWriter(result);

    // Inject some info about android version and the device, since google can't provide them in the
    // developer console
    StackTraceElement[] trace = ex.getStackTrace();
    StackTraceElement[] trace2 = new StackTraceElement[trace.length + 3];
    System.arraycopy(trace, 0, trace2, 0, trace.length);
    trace2[trace.length + 0] =
        new StackTraceElement("Android", "MODEL", android.os.Build.MODEL, -1);
    trace2[trace.length + 1] =
        new StackTraceElement("Android", "VERSION", android.os.Build.VERSION.RELEASE, -1);
    trace2[trace.length + 2] =
        new StackTraceElement("Android", "FINGERPRINT", android.os.Build.FINGERPRINT, -1);
    ex.setStackTrace(trace2);

    ex.printStackTrace(printWriter);
    String stacktrace = result.toString();
    printWriter.close();
    Log.e(TAG, stacktrace);

    // Save the log on SD card if available
    if (Environment.getExternalStorageState().equals(Environment.MEDIA_MOUNTED)) {
      String sdcardPath = Environment.getExternalStorageDirectory().getPath();
      writeLog(stacktrace, sdcardPath + "/vlc_crash");
      writeLogcat(sdcardPath + "/vlc_logcat");
    }

    defaultUEH.uncaughtException(thread, ex);
  }
コード例 #3
0
 @Override
 public void uncaughtException(Thread thread, final Throwable throwable) {
   String now = new SimpleDateFormat("yy-MM-dd HH:mm:ss", Locale.getDefault()).format(new Date());
   final String fullPath = crashDir + now + ".txt";
   if (!FileUtils.createOrExistsFile(fullPath)) return;
   new Thread(
           new Runnable() {
             @Override
             public void run() {
               PrintWriter pw = null;
               try {
                 pw = new PrintWriter(new FileWriter(fullPath, false));
                 pw.write(getCrashHead());
                 throwable.printStackTrace(pw);
                 Throwable cause = throwable.getCause();
                 while (cause != null) {
                   cause.printStackTrace(pw);
                   cause = cause.getCause();
                 }
               } catch (IOException e) {
                 e.printStackTrace();
               } finally {
                 CloseUtils.closeIO(pw);
               }
             }
           })
       .start();
   if (mHandler != null) {
     mHandler.uncaughtException(thread, throwable);
   }
 }
コード例 #4
0
  public void uncaughtException(Thread thread, Throwable exception) {
    if (Constants.FILES_PATH == null) {
      // If the files path is null, the exception can't be stored
      // Always call the default handler instead
      defaultExceptionHandler.uncaughtException(thread, exception);
    } else {
      saveException(exception, thread, listener);

      if (!ignoreDefaultHandler) {
        defaultExceptionHandler.uncaughtException(thread, exception);
      } else {
        android.os.Process.killProcess(android.os.Process.myPid());
        System.exit(10);
      }
    }
  }
コード例 #5
0
ファイル: BTreeStorage.java プロジェクト: chenzuo/Lealone
 private void panic(IllegalStateException e) {
   if (backgroundExceptionHandler != null) {
     backgroundExceptionHandler.uncaughtException(null, e);
   }
   panicException = e;
   closeImmediately();
   throw e;
 }
コード例 #6
0
ファイル: BTreeStorage.java プロジェクト: chenzuo/Lealone
  /** Commit and save all changes, if there are any, and compact the storage if needed. */
  public void writeInBackground(int autoCommitDelay) {
    if (closed) {
      return;
    }

    // could also commit when there are many unsaved pages,
    // but according to a test it doesn't really help
    long time = getTimeSinceCreation();
    if (time <= lastCommitTime + autoCommitDelay) {
      return;
    }
    if (hasUnsavedChanges()) {
      try {
        commitAndSave();
      } catch (Exception e) {
        if (backgroundExceptionHandler != null) {
          backgroundExceptionHandler.uncaughtException(null, e);
          return;
        }
      }
    }
    if (autoCompactFillRate > 0 && lastChunk != null && lastChunk.fileStorage != null) {
      FileStorage fileStorage = lastChunk.fileStorage;
      try {
        // whether there were file read or write operations since
        // the last time
        boolean fileOps;
        long fileOpCount = fileStorage.getWriteCount() + fileStorage.getReadCount();
        if (autoCompactLastFileOpCount != fileOpCount) {
          fileOps = true;
        } else {
          fileOps = false;
        }
        // use a lower fill rate if there were any file operations
        int fillRate = fileOps ? autoCompactFillRate / 3 : autoCompactFillRate;
        // TODO how to avoid endless compaction if there is a bug
        // in the bookkeeping?
        compact(fillRate, autoCommitMemory);
        autoCompactLastFileOpCount = fileStorage.getWriteCount() + fileStorage.getReadCount();
      } catch (Exception e) {
        if (backgroundExceptionHandler != null) {
          backgroundExceptionHandler.uncaughtException(null, e);
        }
      }
    }
  }
コード例 #7
0
ファイル: BTreeStorage.java プロジェクト: chenzuo/Lealone
 /**
  * Close the file and the storage, without writing anything. This will stop the background thread.
  * This method ignores all errors.
  */
 private void closeImmediately() {
   try {
     closeStorage();
   } catch (Exception e) {
     if (backgroundExceptionHandler != null) {
       backgroundExceptionHandler.uncaughtException(null, e);
     }
   }
 }
コード例 #8
0
 /**
  * Write down the stack trace information to the bug report file. This method is called when
  * uncatched exception occurred.
  */
 @Override
 public void uncaughtException(Thread thread, Throwable throwable) {
   PrintWriter printWriter = null;
   try {
     printWriter = new PrintWriter(sContext.openFileOutput(BUG_FILE_NAME, Context.MODE_PRIVATE));
     throwable.printStackTrace(printWriter);
   } catch (FileNotFoundException e) {
     e.printStackTrace();
   } finally {
     if (printWriter != null) printWriter.close();
   }
   sUncaughtExceptionHandler.uncaughtException(thread, throwable);
 }
コード例 #9
0
 @Override
 public void uncaughtException(Thread thread, Throwable ex) {
   if (!handleExption(thread, ex) && defaulthandler != null) { // 如果用户没有处理则让系统默认的异常处理器来处理
     defaulthandler.uncaughtException(thread, ex);
   } else { // Sleep一会后结束程序
     try {
       Thread.sleep(3000);
     } catch (InterruptedException e) {
     }
     android.os.Process.killProcess(android.os.Process.myPid());
     System.exit(10);
   }
 }
コード例 #10
0
 /** 当UncaughtException发生时会转入该函数来处理 */
 @Override
 public void uncaughtException(Thread thread, Throwable ex) {
   if (!handleException(ex) && mDefaultHandler != null) {
     // 如果用户没有处理则让系统默认的异常处理器来处理
     mDefaultHandler.uncaughtException(thread, ex);
   } else {
     try {
       Thread.sleep(3000);
     } catch (InterruptedException e) {
       Log.e(TAG, "error : ", e);
     }
     // 退出程序
     android.os.Process.killProcess(android.os.Process.myPid());
     System.exit(1);
   }
 }
コード例 #11
0
    @Override
    public void uncaughtException(final Thread thread, final Throwable ex) {
      File file = getAppPath(EXCEPTION_PATH);
      try {
        ByteArrayOutputStream out = new ByteArrayOutputStream();
        PrintStream printStream = new PrintStream(out);
        ex.printStackTrace(printStream);
        StringBuilder msg = new StringBuilder();
        msg.append("Version  " + Version.getFullVersion(OsmandApplication.this) + "\n")
            . //$NON-NLS-1$
            append(DateFormat.format("dd.MM.yyyy h:mm:ss", System.currentTimeMillis()));
        try {
          PackageInfo info = getPackageManager().getPackageInfo(getPackageName(), 0);
          if (info != null) {
            msg.append("\nApk Version : ")
                .append(info.versionName)
                .append(" ")
                .append(info.versionCode); // $NON-NLS-1$ //$NON-NLS-2$
          }
        } catch (Throwable e) {
        }
        msg.append("\n")
            . //$NON-NLS-1$//$NON-NLS-2$
            append("Exception occured in thread " + thread.toString() + " : \n")
            . //$NON-NLS-1$ //$NON-NLS-2$
            append(new String(out.toByteArray()));

        if (file.getParentFile().canWrite()) {
          BufferedWriter writer = new BufferedWriter(new FileWriter(file, true));
          writer.write(msg.toString());
          writer.close();
        }
        if (routingHelper.isFollowingMode()) {
          AlarmManager mgr = (AlarmManager) getSystemService(Context.ALARM_SERVICE);
          mgr.set(AlarmManager.RTC, System.currentTimeMillis() + 2000, intent);
          System.exit(2);
        }
        defaultHandler.uncaughtException(thread, ex);
      } catch (Exception e) {
        // swallow all exceptions
        android.util.Log.e(
            PlatformUtil.TAG, "Exception while handle other exception", e); // $NON-NLS-1$
      }
    }
コード例 #12
0
  @Override
  public void uncaughtException(Thread thread, Throwable ex) {
    // Delete the last trace file!
    removeLastTraceFile();

    // Open the file and delete if it already exists
    String filename = buildTraceFileName();
    File f = new File(filename);

    try {
      // Write the stacktrace to the file
      PrintWriter printer = new PrintWriter(f);
      // Print Debug info
      printer.write("== Device Info ==\n");
      printer.write(
          "\nOS Version: "
              + android.os.Build.VERSION.RELEASE
              + " ("
              + System.getProperty("os.version")
              + ")");
      printer.write("\nOS API Level: " + android.os.Build.VERSION.SDK_INT);
      printer.write("\nDevice: " + android.os.Build.DEVICE);
      printer.write(
          "\nModel (and Product): "
              + android.os.Build.MODEL
              + " ("
              + android.os.Build.PRODUCT
              + ")");
      PackageInfo pInfo = mContext.getPackageManager().getPackageInfo(mContext.getPackageName(), 0);
      printer.write("\nApp Version: " + pInfo.versionName + " (" + pInfo.versionCode + ")");

      printer.write(
          "\n\nMax memory: "
              + Runtime.getRuntime().maxMemory()); // the maximum memory the app can use
      printer.write("\nCurrent heap: " + Runtime.getRuntime().totalMemory()); // current heap size
      printer.write(
          "\nHeap available: " + Runtime.getRuntime().freeMemory()); // amount available in heap
      printer.write(
          "\nNative Heap: "
              + Debug.getNativeHeapAllocatedSize()); // is this right? I only want to account for
      // native memory that my app is being "charged"
      // for.  Is this the proper way to account for
      // that?

      // Print stacktrace
      printer.write("\n\n== Stacktrace ==\n\n");
      ex.printStackTrace(printer);
      printer.close();
    } catch (FileNotFoundException e) {
      e.printStackTrace();
    } catch (NameNotFoundException e) {
    }

    // Save the new filename
    SharedPreferences.Editor edit = mSharedPref.edit();
    edit.putString(App.SP_LAST_STACKTRACE, filename);
    edit.commit();

    // Call the default uncaught Exception handler to tell the
    // system, that this app crashed
    mDefaultUEH.uncaughtException(thread, ex);
  }
コード例 #13
0
 @Override
 public void uncaughtException(Thread th, Throwable ex) {
   ex.printStackTrace();
   orig_handler.uncaughtException(th, ex);
 }