Skip to content

Commit

Permalink
[TIMOB-25963] Handle uncaught java exceptions
Browse files Browse the repository at this point in the history
  • Loading branch information
Gary Mathews committed Apr 18, 2018
1 parent d236df6 commit 68ccd97
Showing 1 changed file with 18 additions and 12 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -362,20 +362,26 @@ public void onCreate()
super.onCreate();
Log.d(TAG, "Application onCreate", Log.DEBUG_MODE);

final UncaughtExceptionHandler defaultHandler = Thread.getDefaultUncaughtExceptionHandler();
// handle uncaught java exceptions
Thread.setDefaultUncaughtExceptionHandler(new UncaughtExceptionHandler() {
public void uncaughtException(Thread t, Throwable e)
{
if (isAnalyticsEnabled()) {
String tiVer = buildVersion + "," + buildTimestamp + "," + buildHash;
Log.e(TAG,
"Sending event: exception on thread: " + t.getName() + " msg:" + e.toString() + "; Titanium "
+ tiVer,
e);
TiPlatformHelper.getInstance().postAnalyticsEvent(
TiAnalyticsEventFactory.createErrorEvent(t, e, tiVer));
@Override
public void uncaughtException(Thread t, Throwable e) {

// obtain java stack trace
String javaStack = "";
StackTraceElement[] frames = e.getCause() != null ? e.getCause().getStackTrace() : e.getStackTrace();
for (StackTraceElement frame : frames) {
javaStack += "\n " + frame.toString();
}
defaultHandler.uncaughtException(t, e);

// construct exception message
String message = e.getMessage();
if (!javaStack.isEmpty()) {
message += javaStack;
}

// throw exception as KrollException
KrollRuntime.dispatchException("Runtime Error", message, null, 0, null, 0);
}
});

Expand Down

0 comments on commit 68ccd97

Please sign in to comment.