mirror of
https://github.com/magefree/mage.git
synced 2025-12-20 02:30:08 -08:00
GUI: added new error dialog for more use cases
This commit is contained in:
parent
4f9c158c40
commit
bad782244f
2 changed files with 26 additions and 5 deletions
|
|
@ -1578,6 +1578,7 @@ public class MageFrame extends javax.swing.JFrame implements MageClient {
|
||||||
// FIRST GUI CALL (create main window with all prepared frames, dialogs, etc)
|
// FIRST GUI CALL (create main window with all prepared frames, dialogs, etc)
|
||||||
try {
|
try {
|
||||||
instance = new MageFrame();
|
instance = new MageFrame();
|
||||||
|
EDTExceptionHandler.registerMainApp(instance);
|
||||||
} catch (Throwable e) {
|
} catch (Throwable e) {
|
||||||
LOGGER.fatal("Critical error on start up, app will be closed: " + e.getMessage(), e);
|
LOGGER.fatal("Critical error on start up, app will be closed: " + e.getMessage(), e);
|
||||||
System.exit(1);
|
System.exit(1);
|
||||||
|
|
|
||||||
|
|
@ -1,17 +1,23 @@
|
||||||
|
|
||||||
|
|
||||||
package mage.client.util;
|
package mage.client.util;
|
||||||
|
|
||||||
|
import mage.client.MageFrame;
|
||||||
import org.apache.log4j.Logger;
|
import org.apache.log4j.Logger;
|
||||||
|
|
||||||
|
import java.util.HashMap;
|
||||||
|
import java.util.Map;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
* GUI helper class - catch all app's unhandled errors
|
||||||
*
|
*
|
||||||
* @author BetaSteward_at_googlemail.com
|
* @author BetaSteward_at_googlemail.com, JayDi85
|
||||||
*/
|
*/
|
||||||
public class EDTExceptionHandler implements Thread.UncaughtExceptionHandler {
|
public class EDTExceptionHandler implements Thread.UncaughtExceptionHandler {
|
||||||
|
|
||||||
private static final Logger logger = Logger.getLogger(EDTExceptionHandler.class);
|
private static final Logger logger = Logger.getLogger(EDTExceptionHandler.class);
|
||||||
|
|
||||||
|
private static final Map<String, Integer> foundErrors = new HashMap<>();
|
||||||
|
private static MageFrame mainApp = null; // app to show error dialogs
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void uncaughtException(Thread t, Throwable e) {
|
public void uncaughtException(Thread t, Throwable e) {
|
||||||
handle(e);
|
handle(e);
|
||||||
|
|
@ -20,8 +26,18 @@ public class EDTExceptionHandler implements Thread.UncaughtExceptionHandler {
|
||||||
public void handle(Throwable throwable) {
|
public void handle(Throwable throwable) {
|
||||||
try {
|
try {
|
||||||
logger.fatal("MAGE Client UI error", throwable);
|
logger.fatal("MAGE Client UI error", throwable);
|
||||||
// JOptionPane.showMessageDialog(MageFrame.getDesktop(), throwable, "MAGE Client UI error", JOptionPane.ERROR_MESSAGE);
|
|
||||||
} catch (Throwable t) {}
|
// show error dialog for better users feedback about client side errors
|
||||||
|
// with some protection from dialogs spam on screen (e.g. on render/graphic errors)
|
||||||
|
String errorKey = throwable.toString();
|
||||||
|
int foundCount = foundErrors.getOrDefault(errorKey, 0);
|
||||||
|
if (foundCount < 5 && mainApp != null) {
|
||||||
|
mainApp.showErrorDialog("CLIENT - unhandled error in GUI", throwable);
|
||||||
|
foundCount++;
|
||||||
|
}
|
||||||
|
foundErrors.put(errorKey, foundCount++);
|
||||||
|
} catch (Throwable ignore) {
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
public static void registerExceptionHandler() {
|
public static void registerExceptionHandler() {
|
||||||
|
|
@ -29,4 +45,8 @@ public class EDTExceptionHandler implements Thread.UncaughtExceptionHandler {
|
||||||
System.setProperty("sun.awt.exception.handler", EDTExceptionHandler.class.getName());
|
System.setProperty("sun.awt.exception.handler", EDTExceptionHandler.class.getName());
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public static void registerMainApp(MageFrame app) {
|
||||||
|
mainApp = app;
|
||||||
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue