import net.sf.openrocket.gui.dialogs.BugReportDialog;
import net.sf.openrocket.logging.LogHelper;
+import net.sf.openrocket.logging.TraceException;
import net.sf.openrocket.startup.Application;
if (isOutOfMemoryError(throwable)) {
memoryReserve = null;
handling = false;
- log.warn("Out of memory error detected", throwable);
+ log.error("Out of memory error detected", throwable);
}
if (isNonFatalJREBug(throwable)) {
return;
}
- log.warn("Handling uncaught exception on thread=" + thread, throwable);
+ log.error("Handling uncaught exception on thread=" + thread, throwable);
throwable.printStackTrace();
if (handling) {
} else {
log.info("Exception handler not on EDT, invoking dialog on EDT");
SwingUtilities.invokeAndWait(new Runnable() {
+ @Override
public void run() {
showDialog(thread, throwable);
}
log.error("Caught exception while handling exception", ex);
System.err.println("Exception in exception handler, dumping exception:");
ex.printStackTrace();
- } catch (Throwable ignore) {
+ } catch (Exception ignore) {
}
} finally {
/**
* Handle an error condition programmatically without throwing an exception.
* This can be used in cases where recovery of the error is desirable.
+ * <p>
+ * This method is guaranteed never to throw an exception, and can thus be safely
+ * used in finally blocks.
*
* @param message the error message.
*/
public static void handleErrorCondition(String message) {
- log.error(1, message);
+ log.error(1, message, new TraceException());
handleErrorCondition(new InternalException(message));
}
/**
* Handle an error condition programmatically without throwing an exception.
* This can be used in cases where recovery of the error is desirable.
+ * <p>
+ * This method is guaranteed never to throw an exception, and can thus be safely
+ * used in finally blocks.
*
* @param message the error message.
* @param exception the exception that occurred.
*/
- public static void handleErrorCondition(String message, Exception exception) {
+ public static void handleErrorCondition(String message, Throwable exception) {
log.error(1, message, exception);
handleErrorCondition(new InternalException(message, exception));
}
/**
* Handle an error condition programmatically without throwing an exception.
* This can be used in cases where recovery of the error is desirable.
+ * <p>
+ * This method is guaranteed never to throw an exception, and can thus be safely
+ * used in finally blocks.
*
* @param exception the exception that occurred.
*/
- public static void handleErrorCondition(final Exception exception) {
- if (!(exception instanceof InternalException)) {
- log.error(1, "Error occurred", exception);
- }
- final ExceptionHandler handler = instance;
- final Thread thread = Thread.currentThread();
-
+ public static void handleErrorCondition(final Throwable exception) {
try {
+ if (!(exception instanceof InternalException)) {
+ log.error(1, "Error occurred", exception);
+ }
+ final Thread thread = Thread.currentThread();
+ final ExceptionHandler handler = instance;
if (handler == null) {
- // Not initialized, simply print the exception
- log.error("Exception handler not initialized");
- exception.printStackTrace();
+ log.error("Error condition occurred before exception handling has been initialized", exception);
return;
}
log.info("Running in EDT, showing dialog");
handler.showDialog(thread, exception);
} else {
- log.info("Not in EDT, invoking and waiting for dialog");
- SwingUtilities.invokeAndWait(new Runnable() {
+ log.info("Not in EDT, invoking dialog later");
+ SwingUtilities.invokeLater(new Runnable() {
+ @Override
public void run() {
handler.showDialog(thread, exception);
}
});
}
} catch (Exception e) {
- log.error("Exception occurred while showing error dialog", e);
- e.printStackTrace();
+ log.error("Exception occurred in error handler", e);
}
}
}
// Unknown Error
- if (!(e instanceof Exception)) {
+ if (!(e instanceof Exception) && !(e instanceof LinkageError)) {
log.info("Showing Error dialog");
JOptionPane.showMessageDialog(null,
new Object[] {
*/
private static boolean isNonFatalJREBug(Throwable t) {
+ // NOTE: Calling method logs the entire throwable, so log only message here
+
/*
* Detect and ignore bug 6828938 in Sun JRE 1.6.0_14 - 1.6.0_16.
*/
}
}
+
+ /*
+ * Detect and ignore bug 6933331 in Sun JRE 1.6.0_18 and others
+ */
+ if (t instanceof IllegalStateException) {
+ StackTraceElement[] trace = t.getStackTrace();
+
+ if (trace.length > 1 &&
+ trace[0].getClassName().equals("sun.awt.windows.WComponentPeer") &&
+ trace[0].getMethodName().equals("getBackBuffer")) {
+ log.warn("Ignoring Sun JRE bug 6933331 " +
+ "(see http://bugs.sun.com/bugdatabase/view_bug.do?bug_id=6933331): " + t);
+ return true;
+ }
+ }
+
/*
* Detect and ignore bug in Sun JRE 1.6.0_19
*/
return true;
}
}
+
+ /*
+ * Detect Sun JRE bug in D3D
+ */
+ if (t instanceof ClassCastException) {
+ if (t.getMessage().equals("sun.awt.Win32GraphicsConfig cannot be cast to sun.java2d.d3d.D3DGraphicsConfig")) {
+ log.warn("Ignoring Sun JRE bug " +
+ "(see http://forums.sun.com/thread.jspa?threadID=5440525): " + t);
+ return true;
+ }
+ }
+
return false;
}