Results 1 to 4 of 4

Thread: ErrorUtils.reportException...

  1. #1

    Default ErrorUtils.reportException...

    Where is this ErrorUtils. that I see in many posts?

    Or the better question would be: What is the best way to display unexpected runtime errors?

  2. #2
    Join Date
    Aug 2005
    Location
    Austin, TX
    Posts
    425

    Default

    Those probably came from my posts and the ErrorUtils class is unique to my application, it is not part of the RCP framework.

    You can use any mechanism you want to report an error. In my code the ErrorUtils code sends an email to a known email address (so the development team knows immediately of program errors) and then it presents a dialog to the user. The ErrorDialog is a simple extension of MessageDialog that shows the error, the operation being attempted and the stack trace.

    Larry.

  3. #3
    Join Date
    Aug 2005
    Location
    London (the English one!)
    Posts
    378

    Default

    Hi Larry,

    Welcome back.

    A side question, how do you capture your exceptions? Do you pepper your programme with try/catches (sometimes exceptions are "swept under the carpet" in the binding mechanism) or do you rely on the default reporter? Or any other mechanism?

    Thanks

    Benoit

  4. #4
    Join Date
    Aug 2005
    Location
    Austin, TX
    Posts
    425

    Default

    I use a try/catch around the application launch and I install event handlers for all other uncaught exceptions. I've posted the main class for one of my applications below to show what I mean.

    Larry.

    Code:
    package com.fhm.pdbm;
    
    import java.io.File;
    import java.lang.Thread.UncaughtExceptionHandler;
    
    import org.apache.commons.logging.Log;
    import org.apache.commons.logging.LogFactory;
    import org.springframework.richclient.application.ApplicationLauncher;
    
    import com.fhm.pdbm.error.ErrorUtils;
    
    /**
     * Main driver that starts the Physician Database Manager (PDBM) application
     * 
     * @author lstreepy
     * 
     */
    public class PDBManager {
    
        private static Log _logger;
    
        /**
         * MAIN
         * 
         * @param args
         */
        public static void main(String[] args) {
            try {
                // Before we do anything, try to create the product root directory in
                // the users home directory
                createProductDir();
    
                // Now we can create out logger
                _logger = LogFactory.getLog( PDBManager.class );
    
                _logger.info( "PDBManager starting up" );
    
                // Install a general unhandled exception handler
                Thread.setDefaultUncaughtExceptionHandler( new UEHandler() );
                AWTExceptionHandler.register();
    
                String rootContext = "/com/fhm/pdbm/ctx";
    
                String startupContext = rootContext + "/startup-context.xml";
                String applicationContext = rootContext + "/application-context.xml";
                String businessLayerContext = rootContext + "/business-layer-context.xml";
                String securityContext = rootContext + "/security-context.xml";
    
                new ApplicationLauncher( startupContext, new String[] { applicationContext, businessLayerContext, securityContext } );
            } catch( Exception e ) {
                ErrorUtils.reportException( "Application Startup", e );
                System.exit( 1 );
            }
    
        }
    
        /**
         * Create the product root directory.
         */
        private static void createProductDir() {
            File dir = new File( System.getProperty( "user.home" ), ".pdbm" );
            if( !dir.exists() ) {
                dir.mkdirs();
            }
        }
    
        /**
         * Class to handle uncaught exceptions.
         */
        private static class UEHandler implements UncaughtExceptionHandler {
    
            public void uncaughtException(Thread t, Throwable e) {
                String op = "Action on thread: " + t.getName();
                ErrorUtils.reportException( op, e );
            }
        }
    
        /**
         * Another class to handle uncaught exceptions, this one for the AWT event thread.
         * Since the AWT event thread catches exceptions (and just spits out a stack trace),
         * they won't be "uncaught" and the handler above won't get invoked.
         */
        public static class AWTExceptionHandler {
    
            public static void register() {
                System.setProperty( "sun.awt.exception.handler", AWTExceptionHandler.class.getName() );
            }
    
            public void handle(Throwable e) {
                ErrorUtils.reportException( "Exception on AWT Event Thread", e );
            }
        }
    }

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •