last update: 06/28/2004 15:57:55

Error handling

jConfig is designed in a way that it will never crash your application. The error messages and exception are kept internal. This can be a downfall if you are facing strange behaviour. When you are sure you have the configuration file in the classpath but you get an empty configuration from jConfig then it was hard to find the error.
This new version now includes an ErrorHandler that you can switch on to find any problems.
The default error handler will not report any errors. There is a error handler included that will write out any message or exception to the console.

There are two ways of setting the ErrorHandler.

1. system property

You set a system property with the error handler:
System.setProperty("jconfig.errorhandler","org.jconfig.error.SimpleErrorHandler");

2. put an entry in the jconfig.properties

Create a file called jconfig.properties and put in the following line:
jconfig.errorhandler=org.jconfig.error.SimpleErrorHandler

If none of the above is set then the default NullDeviceErrorHandler is used.

You can also write your own error handler. All you need is to implement the org.jconfig.error.ErrorHandler interface and define your error handler with the full qualified class name.

Example:

package org.foo.myapp.config;

public class MySimpleErrorHandler implements ErrorHandler {

  public MySimpleErrorHandler() {		
  }
	
  public void reportError(String message) {
    System.out.println(message);
  }

	
  public void reportError(String message, Throwable thrown) {
    // do something here like send an email or call someone
    System.out.println(message);
    thrown.printStackTrace();
  }		
}

and then define it like this:

jconfig.errorhandler=org.foo.myapp.config.MySimpleErrorHandler