edu.rice.cs.drjava.model
Class MultiThreadedTestCase.ExceptionHandler

java.lang.Object
  extended by edu.rice.cs.drjava.model.MultiThreadedTestCase.ExceptionHandler
All Implemented Interfaces:
Thread.UncaughtExceptionHandler
Enclosing class:
MultiThreadedTestCase

private static class MultiThreadedTestCase.ExceptionHandler
extends Object
implements Thread.UncaughtExceptionHandler

Class that stores exceptions thrown in other threads so they can be rethrown in the main thread. AssertionFailedErrors thrown in other threads do not count as AssertionFailedErrors in the main class, i.e. if an assertion fails in a thread that is not the main thread, the unit test will not fail!


Field Summary
private  Throwable _e
          Stored throwable, or null if nothing stored.
private  Thread _mainThread
          Thread that spawns the other threads.
private  Thread _t
          Stored thread that threw or null if none.
static MultiThreadedTestCase.ExceptionHandler ONLY
          Singleton instance.
 
Constructor Summary
private MultiThreadedTestCase.ExceptionHandler()
          Singleton constructor.
 
Method Summary
 boolean exceptionOccurred()
          Returns true if an exception has occurred.
 Throwable getException()
           
 Thread getThread()
           
 void reset()
          Reset the stored exception and thread.
 void rethrow()
          Rethrow the exception, if one was stored.
 void setMainThread(Thread mainThread)
          Set the thread that spawns the other threads.
 void uncaughtException(Thread t, Throwable e)
          Gets called if an uncaught exception occurs in a thread.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

_e

private volatile Throwable _e
Stored throwable, or null if nothing stored.


_t

private volatile Thread _t
Stored thread that threw or null if none.


_mainThread

private volatile Thread _mainThread
Thread that spawns the other threads.


ONLY

public static final MultiThreadedTestCase.ExceptionHandler ONLY
Singleton instance.

Constructor Detail

MultiThreadedTestCase.ExceptionHandler

private MultiThreadedTestCase.ExceptionHandler()
Singleton constructor.

Method Detail

uncaughtException

public void uncaughtException(Thread t,
                              Throwable e)
Gets called if an uncaught exception occurs in a thread.

Specified by:
uncaughtException in interface Thread.UncaughtExceptionHandler
Parameters:
t - the thread
e - the uncaught exception

reset

public void reset()
Reset the stored exception and thread.


rethrow

public void rethrow()
Rethrow the exception, if one was stored.


exceptionOccurred

public boolean exceptionOccurred()
Returns true if an exception has occurred.

Returns:
true if exception has occurred

getException

public Throwable getException()

getThread

public Thread getThread()

setMainThread

public void setMainThread(Thread mainThread)
Set the thread that spawns the other threads.