diff options
author | steckbrief <steckbrief@chefmail.de> | 2015-05-03 22:25:46 +0200 |
---|---|---|
committer | lookshe <github@lookshe.org> | 2015-06-19 09:46:40 +0200 |
commit | 7382e3af9769f76fe4e19934a59e45a3f9858332 (patch) | |
tree | c37cdb03dfaeaccde7c8dd7c79887bf0de278f83 /src/main/java/de/thedevstack/conversationsplus/utils/ExceptionHandler.java | |
parent | b3b4a2902e37fb072e800f5dff0392755f5d4501 (diff) |
renaming eu.siacs.conversations to de.thedevstack.conversationsplus
"renaming eu.siacs.conversations to de.thedevstack.conversationsplus"
package renaming completed
Diffstat (limited to 'src/main/java/de/thedevstack/conversationsplus/utils/ExceptionHandler.java')
-rw-r--r-- | src/main/java/de/thedevstack/conversationsplus/utils/ExceptionHandler.java | 46 |
1 files changed, 46 insertions, 0 deletions
diff --git a/src/main/java/de/thedevstack/conversationsplus/utils/ExceptionHandler.java b/src/main/java/de/thedevstack/conversationsplus/utils/ExceptionHandler.java new file mode 100644 index 00000000..256287f1 --- /dev/null +++ b/src/main/java/de/thedevstack/conversationsplus/utils/ExceptionHandler.java @@ -0,0 +1,46 @@ +package de.thedevstack.conversationsplus.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()); + os.flush(); + os.close(); + } 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); + } + +} |