示例#1
0
  @Override
  public void onCreate() {
    super.onCreate();
    // 程序入口
    Logger.d(TAG, "应用程序启动");
    //
    // // 监控全局 初始化
    // Thread.setDefaultUncaughtExceptionHandler(new CrashHandler());
    //
    // // int a = 1;
    // // int b = 0;
    // // int c = a / b;

    // The following line triggers the initialization of ACRA
    ACRA.init(this);
    //		ACRA.getErrorReporter().setReportSender(new ReportSender() {
    //
    //			@Override
    //			public void send(Context arg0, CrashReportData data)
    //					throws ReportSenderException {
    //				// TODO Auto-generated method stub
    //
    //
    //			}
    //		});

  }
示例#2
0
    @Override
    public void uncaughtException(Thread thread, Throwable ex) {
      Logger.d(TAG, "捕获异常");

      StringWriter sw = new StringWriter();
      PrintWriter err = new PrintWriter(sw);
      ex.printStackTrace(err);

      String result = sw.toString();

      try {
        FileOutputStream os =
            new FileOutputStream(new File(Environment.getExternalStorageDirectory(), "error.log"));

        os.write(result.getBytes());
        os.close();

        android.os.Process.killProcess(android.os.Process.myPid());
      } catch (Exception e) {
        e.printStackTrace();
      }
    }