From 3654b9bb8841c983f7936305e6c46670f9bbbfbb Mon Sep 17 00:00:00 2001 From: Lodici Date: Thu, 31 Oct 2013 21:25:57 +0000 Subject: [PATCH 1/2] Now displays a message to user when an exception occurs instead of just bombing out. --- src/magic/model/MagicGameReport.java | 21 +++++++++++++++++++++ 1 file changed, 21 insertions(+) diff --git a/src/magic/model/MagicGameReport.java b/src/magic/model/MagicGameReport.java index f299efd497..468c319a38 100644 --- a/src/magic/model/MagicGameReport.java +++ b/src/magic/model/MagicGameReport.java @@ -6,6 +6,7 @@ import magic.model.action.MagicAction; import magic.model.stack.MagicItemOnStack; import magic.ui.VersionPanel; +import java.awt.Desktop; import java.io.File; import java.io.IOException; import java.io.PrintWriter; @@ -13,13 +14,33 @@ import java.io.StringWriter; import java.text.SimpleDateFormat; import java.util.Date; +import javax.swing.JOptionPane; + public class MagicGameReport implements Thread.UncaughtExceptionHandler { public void uncaughtException(final Thread th, final Throwable ex) { MagicGameReport.buildReport(MagicGame.getInstance(), th, ex); + doNotifyUser(); System.exit(1); } + private void doNotifyUser() { + try { + JOptionPane.showMessageDialog( + null, + "An unexpected error has occurred and Magarena will need to close.\n\n" + + "Please consider posting a crash report to the Magarena forum so that the\n" + + "development team can investigate. Full instructions on how to submit a\n" + + "crash report can be found in HELP.txt in the main game directory.\n\n" + + "Magarena will now try to open this directory in your default file manager.", + "Fatal Error", + JOptionPane.ERROR_MESSAGE); + Desktop.getDesktop().open(new File(MagicMain.getGamePath())); + } catch (Exception e) { + // do nothing - crash report has already been generated and app is about to exit anyway. + } + } + private static void buildCard(final MagicGame game,final String place,final MagicCard card,final StringBuilder report) { report.append(" - ").append(place).append(" : ").append(card.getName()).append("\n"); } From 2b42fee5edf32866a98fbca012753a8fce0c4fa7 Mon Sep 17 00:00:00 2001 From: Lodici Date: Fri, 1 Nov 2013 09:48:40 +0000 Subject: [PATCH 2/2] - Update to runtime exception message based on forum feedback. --- src/magic/model/MagicGameReport.java | 46 ++++++++++++++++++++++------ 1 file changed, 36 insertions(+), 10 deletions(-) diff --git a/src/magic/model/MagicGameReport.java b/src/magic/model/MagicGameReport.java index 468c319a38..c887343926 100644 --- a/src/magic/model/MagicGameReport.java +++ b/src/magic/model/MagicGameReport.java @@ -2,6 +2,7 @@ package magic.model; import magic.MagicMain; import magic.data.FileIO; +import magic.data.URLUtils; import magic.model.action.MagicAction; import magic.model.stack.MagicItemOnStack; import magic.ui.VersionPanel; @@ -14,6 +15,7 @@ import java.io.StringWriter; import java.text.SimpleDateFormat; import java.util.Date; +import javax.swing.JFrame; import javax.swing.JOptionPane; public class MagicGameReport implements Thread.UncaughtExceptionHandler { @@ -24,18 +26,42 @@ public class MagicGameReport implements Thread.UncaughtExceptionHandler { System.exit(1); } + /** + * Displays a message to user in the event an unexpected exception occurs. + * User can open logs folder and/or Issue tracker directly from this dialog. + */ private void doNotifyUser() { try { - JOptionPane.showMessageDialog( - null, - "An unexpected error has occurred and Magarena will need to close.\n\n" + - "Please consider posting a crash report to the Magarena forum so that the\n" + - "development team can investigate. Full instructions on how to submit a\n" + - "crash report can be found in HELP.txt in the main game directory.\n\n" + - "Magarena will now try to open this directory in your default file manager.", - "Fatal Error", - JOptionPane.ERROR_MESSAGE); - Desktop.getDesktop().open(new File(MagicMain.getGamePath())); + + // By specifying a frame the JOptionPane will be shown in the taskbar. + // Otherwise if the dialog is hidden it is easy to forget it is still open. + JFrame frame = new JFrame("Fatal Error"); + frame.setUndecorated(true); + frame.setVisible(true); + frame.setLocationRelativeTo(null); + + // Custom option dialog. + Object[] options = {"Open logs folder", "Issue Tracker", "Close"}; + int action = -1; + do { + action = JOptionPane.showOptionDialog( + frame, + "An unexpected error has occurred and Magarena will need to close.\n\n" + + "Please consider posting the crash report (\"crash.log\") to the Magarena\n" + + "forum or Issue Tracker so that the development team can investigate.\n\n", + "Fatal Error", + JOptionPane.YES_NO_CANCEL_OPTION, + JOptionPane.ERROR_MESSAGE, + null, + options, + options[2]); + if (action == JOptionPane.YES_OPTION) { + Desktop.getDesktop().open(new File(MagicMain.getGamePath())); + } else if (action == JOptionPane.NO_OPTION) { + URLUtils.openURL("http://code.google.com/p/magarena/issues/list"); + } + } while (action != JOptionPane.CANCEL_OPTION && action != -1); + } catch (Exception e) { // do nothing - crash report has already been generated and app is about to exit anyway. }