You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@pivot.apache.org by rw...@apache.org on 2015/06/11 20:26:36 UTC
svn commit: r1684960 - in /pivot/trunk/wtk/src/org/apache/pivot/wtk:
ApplicationContext.java BrowserApplicationContext.java
DesktopApplicationContext.java
Author: rwhitcomb
Date: Thu Jun 11 18:26:36 2015
New Revision: 1684960
URL: http://svn.apache.org/r1684960
Log:
PIVOT-969: Fix the broken build because the concrete instances of ApplicationContext
don't actually implement the UncaughtExceptionHandler interface. So, fix this by
implementing in ApplicationContext itself. Also rearrange the exception handling
there. Make an override of "handleUncaughtException" to handle either with or without
the thread. Then modify the "catch" statements in the ApplicationContext subclasses
to catch "Throwable" instead of "Exception". Make a "finally" clause in a couple of
places to remove the application at the end, no matter if an exception is thrown.
Note: this still doesn't address how to set the uncaught exception handler in threads
we create (such as for Task). Still working that out.
Modified:
pivot/trunk/wtk/src/org/apache/pivot/wtk/ApplicationContext.java
pivot/trunk/wtk/src/org/apache/pivot/wtk/BrowserApplicationContext.java
pivot/trunk/wtk/src/org/apache/pivot/wtk/DesktopApplicationContext.java
Modified: pivot/trunk/wtk/src/org/apache/pivot/wtk/ApplicationContext.java
URL: http://svn.apache.org/viewvc/pivot/trunk/wtk/src/org/apache/pivot/wtk/ApplicationContext.java?rev=1684960&r1=1684959&r2=1684960&view=diff
==============================================================================
--- pivot/trunk/wtk/src/org/apache/pivot/wtk/ApplicationContext.java (original)
+++ pivot/trunk/wtk/src/org/apache/pivot/wtk/ApplicationContext.java Thu Jun 11 18:26:36 2015
@@ -72,7 +72,7 @@ import org.apache.pivot.wtk.effects.Shad
/**
* Base class for application contexts.
*/
-public abstract class ApplicationContext implements Thread.UncaughtExceptionHandler {
+public abstract class ApplicationContext implements Application.UncaughtExceptionHandler {
/**
* Native display host. This is the Pivot interface with AWT.
*/
@@ -2067,6 +2067,11 @@ public abstract class ApplicationContext
return cursor;
}
+ @Override
+ public void uncaughtException(Thread thread, Throwable exception) {
+ handleUncaughtException(thread, exception);
+ }
+
public static void defaultUncaughtExceptionHandler(Thread thread, Throwable exception) {
exception.printStackTrace();
@@ -2075,7 +2080,7 @@ public abstract class ApplicationContext
return;
}
- String message = exception.getClass().getName();
+ String message = String.format("%1$s on Thread %2$s:", exception.getClass().getName(), thread.getName());
TextArea body = null;
String bodyText = exception.getMessage();
@@ -2090,17 +2095,21 @@ public abstract class ApplicationContext
}
public static void handleUncaughtException(Throwable exception) {
+ handleUncaughtException(Thread.currentThread(), exception);
+ }
+
+ public static void handleUncaughtException(Thread thread, Throwable exception) {
int n = 0;
for (Application application : applications) {
if (application instanceof Application.UncaughtExceptionHandler) {
Application.UncaughtExceptionHandler uncaughtExceptionHandler = (Application.UncaughtExceptionHandler) application;
- uncaughtExceptionHandler.uncaughtException(Thread.currentThread(), exception);
+ uncaughtExceptionHandler.uncaughtException(thread, exception);
n++;
}
}
if (n == 0) {
- defaultUncaughtExceptionHandler(Thread.currentThread(), exception);
+ defaultUncaughtExceptionHandler(thread, exception);
}
}
Modified: pivot/trunk/wtk/src/org/apache/pivot/wtk/BrowserApplicationContext.java
URL: http://svn.apache.org/viewvc/pivot/trunk/wtk/src/org/apache/pivot/wtk/BrowserApplicationContext.java?rev=1684960&r1=1684959&r2=1684960&view=diff
==============================================================================
--- pivot/trunk/wtk/src/org/apache/pivot/wtk/BrowserApplicationContext.java (original)
+++ pivot/trunk/wtk/src/org/apache/pivot/wtk/BrowserApplicationContext.java Thu Jun 11 18:26:36 2015
@@ -232,7 +232,7 @@ public final class BrowserApplicationCon
HostApplet.this.application.startup(
HostApplet.this.displayHost.getDisplay(), new ImmutableMap<>(
HostApplet.this.startupProperties));
- } catch (Exception exception) {
+ } catch (Throwable exception) {
handleUncaughtException(exception);
}
}
@@ -248,13 +248,13 @@ public final class BrowserApplicationCon
if (HostApplet.this.application != null) {
try {
HostApplet.this.application.shutdown(false);
- } catch (Exception exception) {
+ } catch (Throwable exception) {
handleUncaughtException(exception);
+ } finally {
+ // Remove the application from the application list
+ applications.remove(HostApplet.this.application);
+ HostApplet.this.application = null;
}
-
- // Remove the application from the application list
- applications.remove(HostApplet.this.application);
- HostApplet.this.application = null;
}
}
}
Modified: pivot/trunk/wtk/src/org/apache/pivot/wtk/DesktopApplicationContext.java
URL: http://svn.apache.org/viewvc/pivot/trunk/wtk/src/org/apache/pivot/wtk/DesktopApplicationContext.java?rev=1684960&r1=1684959&r2=1684960&view=diff
==============================================================================
--- pivot/trunk/wtk/src/org/apache/pivot/wtk/DesktopApplicationContext.java (original)
+++ pivot/trunk/wtk/src/org/apache/pivot/wtk/DesktopApplicationContext.java Thu Jun 11 18:26:36 2015
@@ -259,19 +259,17 @@ public final class DesktopApplicationCon
case WindowEvent.WINDOW_ICONIFIED: {
try {
application.suspend();
- } catch (Exception exception) {
+ } catch (Throwable exception) {
handleUncaughtException(exception);
}
-
break;
}
case WindowEvent.WINDOW_DEICONIFIED: {
try {
application.resume();
- } catch (Exception exception) {
+ } catch (Throwable exception) {
handleUncaughtException(exception);
}
-
break;
}
default: {
@@ -416,13 +414,13 @@ public final class DesktopApplicationCon
if (application != null) {
try {
cancelShutdown = application.shutdown(optional);
- } catch (Exception exception) {
+ } catch (Throwable exception) {
handleUncaughtException(exception);
- }
-
- if (!cancelShutdown) {
- // Remove the application from the application list
- applications.remove(application);
+ } finally {
+ if (!cancelShutdown) {
+ // Remove the application from the application list
+ applications.remove(application);
+ }
}
}
@@ -656,8 +654,7 @@ public final class DesktopApplicationCon
// Initial configuration of the windows
setFullScreen(fullScreen, visible);
- // TODO This is a workaround for Java bug #6365898 on Linux (fixed
- // only in Java 7),
+ // TODO This is a workaround for Java bug #6365898 on Linux (fixed only in Java 7),
// revisit / remove later when we'll require Java 7
if (maximized && visible) {
windowedHostFrame.setExtendedState(java.awt.Frame.MAXIMIZED_BOTH);
@@ -669,9 +666,8 @@ public final class DesktopApplicationCon
@Override
public void run() {
try {
- application.startup(primaryDisplayHost.getDisplay(), new ImmutableMap<>(
- properties));
- } catch (Exception exception) {
+ application.startup(primaryDisplayHost.getDisplay(), new ImmutableMap<>(properties));
+ } catch (Throwable exception) {
handleUncaughtException(exception);
}
}