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;
-import net.sf.openrocket.util.BugException;
public class ExceptionHandler implements Thread.UncaughtExceptionHandler {
} 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.
/**
* 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 Thread thread = Thread.currentThread();
- final ExceptionHandler handler = instance;
-
- if (handler == null) {
- // Not initialized, throw the exception
- throw new BugException("Error condition before exception handling has been initialized", exception);
- }
-
try {
+ if (!(exception instanceof InternalException)) {
+ log.error(1, "Error occurred", exception);
+ }
+ final Thread thread = Thread.currentThread();
+ final ExceptionHandler handler = instance;
+
+ if (handler == null) {
+ log.error("Error condition occurred before exception handling has been initialized", exception);
+ return;
+ }
+
if (SwingUtilities.isEventDispatchThread()) {
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() {
+ @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);
}
}
*/
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.
*/
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;
}