How to show an error to user?
Post MTG Forge Related Programming Questions Here
Moderators: timmermac, Blacksmith, KrazyTheFox, Agetian, friarsol, CCGHQ Admins
4 posts
• Page 1 of 1
How to show an error to user?
by Max mtg » 04 Sep 2011, 19:51
I've fixed an issue with deck loading. If a deck loaded at startup contains an unsuppored card, forge throwed an exception.
What is a correct way to imform user that some of his decks are not good to play with?
I've made this:
What is a correct way to imform user that some of his decks are not good to play with?
I've made this:
- Code: Select all
public void readAllDecks() {
// some code here
List<String> decksThatFailedToLoad = new ArrayList<String>();
files = deckDir.listFiles(DCKFileFilter);
for (File file : files) {
try {
Deck newDeck = readDeck(file);
deckMap.put(newDeck.getName(), newDeck);
} catch (NoSuchElementException ex) {
String message = String.format("%s failed to load because ---- %s", file.getName(), ex.getMessage());
decksThatFailedToLoad.add(message);
}
}
if (!decksThatFailedToLoad.isEmpty()) {
JOptionPane.showMessageDialog(null, StringUtils.join(decksThatFailedToLoad, System.getProperty("line.separator")),
"Some of your decks were not loaded.", JOptionPane.WARNING_MESSAGE);
}
//here was some more code
}
Single class for single responsibility.
- Max mtg
- Programmer
- Posts: 1997
- Joined: 02 Jul 2011, 14:26
- Has thanked: 173 times
- Been thanked: 334 times
Re: How to show an error to user?
by Rob Cashwalker » 07 Sep 2011, 04:39
JOptionPane.showMessageDialog is for basic one-liner errors or informaional messages.
The Force will be with you, Always.
-
Rob Cashwalker - Programmer
- Posts: 2167
- Joined: 09 Sep 2008, 15:09
- Location: New York
- Has thanked: 5 times
- Been thanked: 40 times
Re: How to show an error to user?
by Max mtg » 07 Sep 2011, 07:55
is it ok to invoke this method from purely utility classes?
If that class has no relation to gui, may be it should return its errors in some other way?
If that class has no relation to gui, may be it should return its errors in some other way?
Single class for single responsibility.
- Max mtg
- Programmer
- Posts: 1997
- Joined: 02 Jul 2011, 14:26
- Has thanked: 173 times
- Been thanked: 334 times
Re: How to show an error to user?
by Rob Cashwalker » 09 Sep 2011, 18:10
It's a standard Message Dialog type of utility function... if you search Google for "Message Dialog Java", it will come up as the answer.
There is also the ErrorViewer class that's in forge.error, which is our custom-built screen for long text errors, with the buttons on the bottom for saving or reporting as a bug.
There is also the ErrorViewer class that's in forge.error, which is our custom-built screen for long text errors, with the buttons on the bottom for saving or reporting as a bug.
The Force will be with you, Always.
-
Rob Cashwalker - Programmer
- Posts: 2167
- Joined: 09 Sep 2008, 15:09
- Location: New York
- Has thanked: 5 times
- Been thanked: 40 times
4 posts
• Page 1 of 1
Who is online
Users browsing this forum: No registered users and 23 guests