It is currently 24 Apr 2024, 01:02
   
Text Size

Error Handling

Post MTG Forge Related Programming Questions Here

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

Error Handling

Postby mtgrares » 21 Aug 2009, 17:38

So Dennis mentioned that Silly Freak greatly improved the error reporting system? That sounds really good. It would be nice when there was an error if MTG Forge saves the error to a file or sends an e-mail if the player is online.
mtgrares
DEVELOPER
 
Posts: 1352
Joined: 08 Sep 2008, 22:10
Has thanked: 3 times
Been thanked: 12 times

Re: Error Handling

Postby silly freak » 21 Aug 2009, 20:11

error saving is not automatic, but a save button is integrated. the error message also contains your mail and the forum address, but the user can also just click the message away

and also errors while file saving are handled this way. so, if you have some read-only location, you can pop up as many error dialogs as you want^^
___

where's the "trust me, that will work!" switch for the compiler?
Laterna Magica - blog, forum, project, 2010/09/06 release!
silly freak
DEVELOPER
 
Posts: 598
Joined: 26 Mar 2009, 07:18
Location: Vienna, Austria
Has thanked: 93 times
Been thanked: 25 times

Re: Error Handling

Postby silly freak » 27 Sep 2009, 11:01

I thought I'd reuse this thread, it's a small addition to the error handling.

Right now, every error is caught by us and reported by ErrorViewer. That's good, but doesn't prevent some errors from slipping through.

the new class forge.error.ExceptionHandler prevents exactly that. It has two mechanisms: One for Java, when a thread terminates because of an exception, and one for AWT. AWT catches the exception and by default prints to System.err. This class alters the behavior to use ErrorViewer.
Code: Select all
/**
 * ExceptionHandler.java
 *
 * Created on 27.09.2009
 */

package forge.error;


import java.lang.Thread.UncaughtExceptionHandler;


/**
 * This class handles all exceptions that weren't caught by showing the error to the user.
 */
public class ExceptionHandler implements UncaughtExceptionHandler {
    static {
        //Tells Java to let this class handle any uncaught exception
        Thread.setDefaultUncaughtExceptionHandler(new ExceptionHandler());
        //Tells AWT to let this class handle any uncaught exception
        System.setProperty("sun.awt.exception.handler", ExceptionHandler.class.getName());
    }
   
    /**
     * Call this at the beginning to make sure that the class is loaded and the static initializer has run
     */
    public static void registerErrorHandling() {
        System.out.println("Error handling registered!");
    }
   
    @Override
    public void uncaughtException(Thread t, Throwable ex) {
        ErrorViewer.showError(ex);
    }
   
    /**
     * This Method is called by AWT when an error is thrown in the event dispatching thread and not caught.
     */
    public void handle(Throwable ex) {
        ErrorViewer.showError(ex);
    }
}
to use the class, you just have to add the import and insert another line right at the top of Gui_NewGame.main:
Code: Select all
ExceptionHandler.registerErrorHandling();
___

where's the "trust me, that will work!" switch for the compiler?
Laterna Magica - blog, forum, project, 2010/09/06 release!
silly freak
DEVELOPER
 
Posts: 598
Joined: 26 Mar 2009, 07:18
Location: Vienna, Austria
Has thanked: 93 times
Been thanked: 25 times

Re: Error Handling

Postby DennisBergkamp » 27 Sep 2009, 16:34

Cool, I've added it.

Is this where I put it though?
Code: Select all
public static void main(String[] args) {
        ExceptionHandler.registerErrorHandling();
       try {
            Object[] o = UIManager.getInstalledLookAndFeels();
Or do I add it into the try block?
User avatar
DennisBergkamp
AI Programmer
 
Posts: 2602
Joined: 09 Sep 2008, 15:46
Has thanked: 0 time
Been thanked: 0 time

Re: Error Handling

Postby silly freak » 27 Sep 2009, 16:54

it doesn't really matter, i think. the things done in this call (that includes the static initializer) aren't critical. i've put it outside.
___

where's the "trust me, that will work!" switch for the compiler?
Laterna Magica - blog, forum, project, 2010/09/06 release!
silly freak
DEVELOPER
 
Posts: 598
Joined: 26 Mar 2009, 07:18
Location: Vienna, Austria
Has thanked: 93 times
Been thanked: 25 times


Return to Developer's Corner

Who is online

Users browsing this forum: No registered users and 65 guests


Who is online

In total there are 65 users online :: 0 registered, 0 hidden and 65 guests (based on users active over the past 10 minutes)
Most users ever online was 4143 on 23 Jan 2024, 08:21

Users browsing this forum: No registered users and 65 guests

Login Form