Advertisement
Guest User

Untitled

a guest
Aug 5th, 2017
61
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 5.18 KB | None | 0 0
  1. public class TopExceptionHandler implements Thread.UncaughtExceptionHandler {
  2. private Thread.UncaughtExceptionHandler defaultUEH;
  3. private Activity app = null;
  4.  
  5. public TopExceptionHandler(Activity app) {
  6. this.defaultUEH = Thread.getDefaultUncaughtExceptionHandler();
  7. this.app = app;
  8. }
  9.  
  10. public void uncaughtException(Thread t, Throwable e) {
  11. StackTraceElement[] arr = e.getStackTrace();
  12. String report = e.toString()+"nn";
  13. report += "--------- Stack trace ---------nn";
  14. for (int i=0; i<arr.length; i++) {
  15. report += " "+arr[i].toString()+"n";
  16. }
  17. report += "-------------------------------nn";
  18.  
  19. // If the exception was thrown in a background thread inside
  20. // AsyncTask, then the actual exception can be found with getCause
  21.  
  22. report += "--------- Cause ---------nn";
  23. Throwable cause = e.getCause();
  24. if(cause != null) {
  25. report += cause.toString() + "nn";
  26. arr = cause.getStackTrace();
  27. for (int i=0; i<arr.length; i++) {
  28. report += " "+arr[i].toString()+"n";
  29. }
  30. }
  31. report += "-------------------------------nn";
  32.  
  33. try {
  34. FileOutputStream trace = app.openFileOutput("stack.trace",
  35. Context.MODE_PRIVATE);
  36. trace.write(report.getBytes());
  37. trace.close();
  38. } catch(IOException ioe) {
  39. // ...
  40. }
  41.  
  42. defaultUEH.uncaughtException(t, e);
  43. }
  44. }
  45.  
  46. @Override
  47. public void onCreate(Bundle savedInstanceState) {
  48. super.onCreate(savedInstanceState);
  49.  
  50. Thread.setDefaultUncaughtExceptionHandler(new TopExceptionHandler(this));
  51. ...
  52.  
  53. try {
  54. BufferedReader reader = new BufferedReader(
  55. new InputStreamReader(ReaderScopeActivity.this.openFileInput("stack.trace")));
  56. while((line = reader.readLine()) != null) {
  57. trace += line+"n";
  58. }
  59. } catch(FileNotFoundException fnfe) {
  60. // ...
  61. } catch(IOException ioe) {
  62. // ...
  63. }
  64.  
  65. Intent sendIntent = new Intent(Intent.ACTION_SEND);
  66. String subject = "Error report";
  67. String body = "Mail this to appdeveloper@gmail.com: " + "n" + trace + "n";
  68.  
  69. sendIntent.putExtra(Intent.EXTRA_EMAIL, new String[] {"readerscope@altcanvas.com"});
  70. sendIntent.putExtra(Intent.EXTRA_TEXT, body);
  71. sendIntent.putExtra(Intent.EXTRA_SUBJECT, subject);
  72. sendIntent.setType("message/rfc822");
  73.  
  74. ReaderScopeActivity.this.startActivity(Intent.createChooser(sendIntent, "Title:"));
  75.  
  76. ReaderScopeActivity.this.deleteFile("stack.trace");
  77.  
  78. @ReportsCrashes(formKey = "", mailTo = "abc@gmail.com;def@yahoo.com", mode = ReportingInteractionMode.SILENT)
  79.  
  80. adb logcat AndroidRuntime:E *:S
  81.  
  82. 09-04 21:35:15.228: ERROR/AndroidRuntime(778): Uncaught handler: thread main exiting due to uncaught exception
  83. 09-04 21:35:15.397: ERROR/AndroidRuntime(778): java.lang.RuntimeException: Unable to start activity ComponentInfo{com.dazlious.android.helloworld/com.dazlious.android.helloworld.main}: java.lang.ArrayIndexOutOfBoundsException
  84. 09-04 21:35:15.397: ERROR/AndroidRuntime(778): at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2268)
  85. 09-04 21:35:15.397: ERROR/AndroidRuntime(778): at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2284)
  86. 09-04 21:35:15.397: ERROR/AndroidRuntime(778): at android.app.ActivityThread.access$1800(ActivityThread.java:112)
  87. 09-04 21:35:15.397: ERROR/AndroidRuntime(778): at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1692)
  88. 09-04 21:35:15.397: ERROR/AndroidRuntime(778): at android.os.Handler.dispatchMessage(Handler.java:99)
  89. 09-04 21:35:15.397: ERROR/AndroidRuntime(778): at android.os.Looper.loop(Looper.java:123)
  90. 09-04 21:35:15.397: ERROR/AndroidRuntime(778): at android.app.ActivityThread.main(ActivityThread.java:3948)
  91. 09-04 21:35:15.397: ERROR/AndroidRuntime(778): at java.lang.reflect.Method.invokeNative(Native Method)
  92. 09-04 21:35:15.397: ERROR/AndroidRuntime(778): at java.lang.reflect.Method.invoke(Method.java:521)
  93. 09-04 21:35:15.397: ERROR/AndroidRuntime(778): at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:782)
  94. 09-04 21:35:15.397: ERROR/AndroidRuntime(778): at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:540)
  95. 09-04 21:35:15.397: ERROR/AndroidRuntime(778): at dalvik.system.NativeStart.main(Native Method)
  96. 09-04 21:35:15.397: ERROR/AndroidRuntime(778): Caused by: java.lang.ArrayIndexOutOfBoundsException
  97. 09-04 21:35:15.397: ERROR/AndroidRuntime(778): at com.example.android.helloworld.main.onCreate(main.java:13)
  98. 09-04 21:35:15.397: ERROR/AndroidRuntime(778): at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1123)
  99. 09-04 21:35:15.397: ERROR/AndroidRuntime(778): at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2231)
  100. 09-04 21:35:15.397: ERROR/AndroidRuntime(778): ... 11 more
  101.  
  102. 09-04 21:35:15.397: ERROR/AndroidRuntime(778): Caused by: java.lang.ArrayIndexOutOfBoundsException
  103. 09-04 21:35:15.397: ERROR/AndroidRuntime(778): at com.example.android.helloworld.main.onCreate(main.java:13)
  104.  
  105. compile 'com.balsikandar.android:crashreporter:1.0.1'
  106.  
  107. CrashRepoter.logException(Exception e)
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement