cdox.util
Class ErrorHandler

java.lang.Object
  extended bycdox.util.ErrorHandler

public class ErrorHandler
extends java.lang.Object

This is a utility class that can be used for, yes, error handling. There are several methods that take a throwable as argument. To use this class to write some exception output into a file/stream, one must use one of the setErrorFile methods to initialize the static fields. Please don't forget to #closeErrorLog the error log after using it (it uses a buffered writer, so maybe there will not even be one char in it if you don't close it).

Version:
May 22nd 2002
Author:
Rutger Bezema, Andreas Schmitz
See Also:
closeErrorLog()

Constructor Summary
ErrorHandler()
           
 
Method Summary
static void closeErrorLog()
          Closes the error log file.
static void log(java.lang.Throwable e)
          Logs the stack trace of the Throwable into the previously set output.
static void log(java.lang.Throwable e, boolean display)
          Writes the stack trace of e into the previously set output, if any.
static void setErrorFile(java.io.File f)
          Sets the output to the file.
static void setErrorFile(java.io.OutputStream out)
          Sets the output to the stream.
static void setErrorFile(java.lang.String s)
          Sets the output to the file that is specified in the String.
static void setLanguage(java.lang.String language)
          If you don't set the language here, the system's default language is used.
static void showMessage(java.lang.Throwable e)
          Shows a standard message dialog containing the localized message of the Throwable.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

ErrorHandler

public ErrorHandler()
Method Detail

setLanguage

public static void setLanguage(java.lang.String language)
If you don't set the language here, the system's default language is used. If it does not exist, english is used.

Parameters:
language - the new language as ISO-3-letter-language code.

setErrorFile

public static void setErrorFile(java.lang.String s)
                         throws java.io.IOException
Sets the output to the file that is specified in the String.

Parameters:
s - the name of the file to write to.
Throws:
java.io.IOException - if the specified path is not writeable.

setErrorFile

public static void setErrorFile(java.io.File f)
                         throws java.io.IOException
Sets the output to the file.

Parameters:
f - the file.
Throws:
java.io.IOException - if the specified file is not writeable.

setErrorFile

public static void setErrorFile(java.io.OutputStream out)
                         throws java.io.IOException
Sets the output to the stream.

Parameters:
out - the stream to write to.
Throws:
java.io.IOException - if the specified stream is not valid.

log

public static void log(java.lang.Throwable e,
                       boolean display)
Writes the stack trace of e into the previously set output, if any. If the display parameter is true, a message is displayed with the localized message of the Throwable.

Parameters:
e - the Throwable.
display - if true, a message dialog is displayed indicating that an error has occured. If the class has been initialized with a file or a string, the location of the log file will also be displayed.

showMessage

public static void showMessage(java.lang.Throwable e)
Shows a standard message dialog containing the localized message of the Throwable. If the class has been initialized with a string or a file, the location of the log is also told.

Parameters:
e - the Throwable.

log

public static void log(java.lang.Throwable e)
Logs the stack trace of the Throwable into the previously set output.

Parameters:
e - the Throwable.

closeErrorLog

public static void closeErrorLog()
Closes the error log file. This one should be called, if the logging mechanism is used!