org.bushe.swing.exception
Class SwingException

java.lang.Object
  extended by java.lang.Throwable
      extended by java.lang.Exception
          extended by org.bushe.swing.exception.SwingException
All Implemented Interfaces:
Serializable

public class SwingException
extends Exception

Aids in troubleshooting Swing application exceptions or any exception where the caller's stack may not be the exception stack (such as producer-consumer patterns that cross threads).

Swing exceptions usually occur on the Swing Event Dispatch Thread, and often occur when code puts events on the EDT. This code is often in a non-EDT thread such as a thread that is receiving data from a server. If the non-EDT threads puts a call on the EDT and that EDT call causes and exception, the stack trace of the exception is lost, and it often difficult or impossible to determine where the non-EDT call came from.

This Exception class is used to handle exceptions that occur when events are posted on the Swing EDT or occur on another thread from the Swing EDT. It includes a "swing" call stack to record from where the event occurred, and overrides so that the exception and the swing calling stack print nicely to logs.

The swing calling stack is different from the cause of the exception since it is gathered before the exception occurs in a different stack from the cause and used after the exception in a new thread occurs.

See Also:
Serialized Form

Field Summary
protected  StackTraceElement[] callingStackTrace
           
 
Constructor Summary
SwingException()
          Default constructor
SwingException(String message)
          Constructor for compatibility with Exception.
SwingException(String message, Throwable cause)
          Constructor for compatibility with Exception Use ClientException(String, Throwable, StackTraceElement[]) instead
SwingException(String message, Throwable cause, StackTraceElement[] callingStack)
          Preferred constructor.
SwingException(Throwable cause)
          Constructor for compatibility with Exception Use ClientException(String, Throwable, StackTraceElement[]) instead
 
Method Summary
 StackTraceElement[] getCallingStack()
          Client exceptions often have two stacks - one thread causes the posting of an action on another thread - usually the Swing EDT thread.
 void printStackTrace(PrintStream ps)
          Calls printWriter(ps, true)
 void printStackTrace(PrintWriter pw)
          Prints the calling stack and the exception stack trace.
 void setCallingStack(StackTraceElement[] swingCallingStack)
          Swing exceptions often have two stacks - one thread causes the posting of an action on another thread - usually the Swing EDT thread.
 
Methods inherited from class java.lang.Throwable
fillInStackTrace, getCause, getLocalizedMessage, getMessage, getStackTrace, initCause, printStackTrace, setStackTrace, toString
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
 

Field Detail

callingStackTrace

protected StackTraceElement[] callingStackTrace
Constructor Detail

SwingException

public SwingException()
Default constructor


SwingException

public SwingException(String message)
Constructor for compatibility with Exception. Use ClientException(String, Throwable, StackTraceElement[]) instead


SwingException

public SwingException(Throwable cause)
Constructor for compatibility with Exception Use ClientException(String, Throwable, StackTraceElement[]) instead


SwingException

public SwingException(String message,
                      Throwable cause)
Constructor for compatibility with Exception Use ClientException(String, Throwable, StackTraceElement[]) instead


SwingException

public SwingException(String message,
                      Throwable cause,
                      StackTraceElement[] callingStack)
Preferred constructor.

Parameters:
message - The message of exception
cause - The cause of the exception in the same call stack
callingStack - the stack trace that the client used to call the exception to occur.
Method Detail

setCallingStack

public void setCallingStack(StackTraceElement[] swingCallingStack)
Swing exceptions often have two stacks - one thread causes the posting of an action on another thread - usually the Swing EDT thread. The other is the stack of the actual thread the exception occurred on, the exception occurs after the post.

Parameters:
swingCallingStack - the stack trace that the client used to cause the exception to occur.

getCallingStack

public StackTraceElement[] getCallingStack()
Client exceptions often have two stacks - one thread causes the posting of an action on another thread - usually the Swing EDT thread. The other is the stack of the actual thread the exception occurred on.

Returns:
the stack trace that the client used to cause the exception to occur.

printStackTrace

public void printStackTrace(PrintStream ps)
Calls printWriter(ps, true)

Overrides:
printStackTrace in class Throwable
Parameters:
ps - the print stream

printStackTrace

public void printStackTrace(PrintWriter pw)
Prints the calling stack and the exception stack trace.

Overrides:
printStackTrace in class Throwable
Parameters:
pw -


Copyright © 2011 Bushe Enterprises, Inc.. All Rights Reserved.