It is currently 12 Sep 2025, 20:06
   
Text Size

How to show an error to user?

Post MTG Forge Related Programming Questions Here

Moderators: timmermac, Blacksmith, KrazyTheFox, Agetian, friarsol, CCGHQ Admins

How to show an error to user?

Postby 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:
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.
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?

Postby 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.
User avatar
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?

Postby 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?
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?

Postby 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.
The Force will be with you, Always.
User avatar
Rob Cashwalker
Programmer
 
Posts: 2167
Joined: 09 Sep 2008, 15:09
Location: New York
Has thanked: 5 times
Been thanked: 40 times


Return to Developer's Corner

Who is online

Users browsing this forum: No registered users and 23 guests

Main Menu

User Menu

Our Partners


Who is online

In total there are 23 users online :: 0 registered, 0 hidden and 23 guests (based on users active over the past 10 minutes)
Most users ever online was 7967 on 09 Sep 2025, 23:08

Users browsing this forum: No registered users and 23 guests

Login Form