Page 1 of 1

How to show an error to user?

PostPosted: 04 Sep 2011, 19:51
by Max mtg
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:
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
    }
But I am not sure, whether DeckManager is a good place to invoke dialogs from there.

Re: How to show an error to user?

PostPosted: 07 Sep 2011, 04:39
by Rob Cashwalker
JOptionPane.showMessageDialog is for basic one-liner errors or informaional messages.

Re: How to show an error to user?

PostPosted: 07 Sep 2011, 07:55
by Max mtg
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?

Re: How to show an error to user?

PostPosted: 09 Sep 2011, 18:10
by Rob Cashwalker
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.