aboutsummaryrefslogtreecommitdiffstats
path: root/src/eu/siacs/conversations/utils
diff options
context:
space:
mode:
authorDaniel Gultsch <daniel@gultsch.de>2014-03-09 13:21:28 +0100
committerDaniel Gultsch <daniel@gultsch.de>2014-03-09 13:21:28 +0100
commitbaf0d6478750bb59e3f883fb7f814a92f27b8a29 (patch)
tree60652babff25bf35dd682540d655a28d8b9d78e1 /src/eu/siacs/conversations/utils
parent05386b5052b29d47e7be2a5acc52fc524862e5a8 (diff)
exception handler
Diffstat (limited to 'src/eu/siacs/conversations/utils')
-rw-r--r--src/eu/siacs/conversations/utils/ExceptionHandler.java41
-rw-r--r--src/eu/siacs/conversations/utils/ExceptionHelper.java11
2 files changed, 52 insertions, 0 deletions
diff --git a/src/eu/siacs/conversations/utils/ExceptionHandler.java b/src/eu/siacs/conversations/utils/ExceptionHandler.java
new file mode 100644
index 000000000..01cfebbbd
--- /dev/null
+++ b/src/eu/siacs/conversations/utils/ExceptionHandler.java
@@ -0,0 +1,41 @@
+package eu.siacs.conversations.utils;
+
+import java.io.FileNotFoundException;
+import java.io.IOException;
+import java.io.OutputStream;
+import java.io.PrintWriter;
+import java.io.StringWriter;
+import java.io.Writer;
+import java.lang.Thread.UncaughtExceptionHandler;
+
+import android.content.Context;
+
+public class ExceptionHandler implements UncaughtExceptionHandler {
+
+ private UncaughtExceptionHandler defaultHandler;
+ private Context context;
+ public ExceptionHandler(Context context) {
+ this.context = context;
+ this.defaultHandler = Thread.getDefaultUncaughtExceptionHandler();
+ }
+ @Override
+ public void uncaughtException(Thread thread, Throwable ex) {
+ Writer result = new StringWriter();
+ PrintWriter printWriter = new PrintWriter(result);
+ ex.printStackTrace(printWriter);
+ String stacktrace = result.toString();
+ printWriter.close();
+ try {
+ OutputStream os = context.openFileOutput("stacktrace.txt",Context.MODE_PRIVATE);
+ os.write(stacktrace.getBytes());
+ } catch (FileNotFoundException e) {
+ // TODO Auto-generated catch block
+ e.printStackTrace();
+ } catch (IOException e) {
+ // TODO Auto-generated catch block
+ e.printStackTrace();
+ }
+ this.defaultHandler.uncaughtException(thread, ex);
+ }
+
+}
diff --git a/src/eu/siacs/conversations/utils/ExceptionHelper.java b/src/eu/siacs/conversations/utils/ExceptionHelper.java
new file mode 100644
index 000000000..def184d0d
--- /dev/null
+++ b/src/eu/siacs/conversations/utils/ExceptionHelper.java
@@ -0,0 +1,11 @@
+package eu.siacs.conversations.utils;
+
+import android.content.Context;
+
+public class ExceptionHelper {
+ public static void init(Context context) {
+ if(!(Thread.getDefaultUncaughtExceptionHandler() instanceof ExceptionHandler)) {
+ Thread.setDefaultUncaughtExceptionHandler(new ExceptionHandler(context));
+ }
+ }
+}