Skip to content

Commit

Permalink
avoiding to display an error dialog when computer is offline and find…
Browse files Browse the repository at this point in the history
  • Loading branch information
cpesch committed Sep 10, 2024
1 parent 046dd64 commit 4ddacd1
Show file tree
Hide file tree
Showing 3 changed files with 7 additions and 5 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,8 @@

package slash.navigation.gui.actions;

import slash.common.helpers.ExceptionHelper;

import javax.swing.*;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -33,8 +33,7 @@
import static javax.swing.JOptionPane.ERROR_MESSAGE;
import static javax.swing.JOptionPane.showMessageDialog;
import static javax.swing.SwingUtilities.invokeLater;
import static slash.common.helpers.ExceptionHelper.getLocalizedMessage;
import static slash.common.helpers.ExceptionHelper.printStackTrace;
import static slash.common.helpers.ExceptionHelper.*;
import static slash.common.system.Platform.getMaximumMemory;

/**
Expand Down Expand Up @@ -68,10 +67,11 @@ public static void handleOutOfMemoryError(OutOfMemoryError e) {
}

public static void handleThrowable(Class clazz, ActionEvent e, Throwable throwable) {
log.severe(format("Unhandled throwable in action %s from event %s: %s, %s", clazz.getName(), e, throwable, printStackTrace(throwable)));
String stacktrace = isComputerOffline(throwable) ? "" : printStackTrace(throwable);
log.severe(format("Unhandled throwable in action %s from event %s: %s, %s", clazz.getName(), e, getLocalizedMessage(throwable), stacktrace));
showMessageDialog(getFrame(),
MessageFormat.format(Application.getInstance().getContext().getBundle().
getString("unhandled-throwable-error"), clazz.getSimpleName(), getLocalizedMessage(throwable), printStackTrace(throwable)),
getString("unhandled-throwable-error"), clazz.getName(), getLocalizedMessage(throwable), stacktrace),
getFrame().getTitle(), ERROR_MESSAGE);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@ public static boolean isComputerOffline(Throwable throwable) {
}

public static String getLocalizedMessage(Throwable throwable) {
if (throwable instanceof UnknownHostException)
if (isComputerOffline(throwable))
return "Your computer is not connected to the Internet and\n" +
"cannot access " + throwable.getMessage() + ".";
return throwable.getLocalizedMessage() != null ? throwable.getLocalizedMessage() : throwable.toString();
Expand Down

0 comments on commit 4ddacd1

Please sign in to comment.