com.googlecode.catchexception.throwable.internal
Class ThrowableHolder

java.lang.Object
  extended by com.googlecode.catchexception.throwable.internal.ThrowableHolder

public class ThrowableHolder
extends Object

Holds a caught throwable per Thread.

Author:
rwoo

Field Summary
private static ThreadLocal<Throwable> caughtThrowable
          The container for the most recently caught throwable.
 
Constructor Summary
ThrowableHolder()
           
 
Method Summary
static
<E extends Throwable>
E
get()
           
static
<E extends Throwable>
void
set(E caughtThrowable)
          Saves the given throwable in caughtThrowable.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

caughtThrowable

private static final ThreadLocal<Throwable> caughtThrowable
The container for the most recently caught throwable.

There is no need to use weak references here as all the code is for testing so that we don't have to care about memory leaks.

Constructor Detail

ThrowableHolder

public ThrowableHolder()
Method Detail

set

public static <E extends Throwable> void set(E caughtThrowable)
Saves the given throwable in caughtThrowable.

Type Parameters:
E - the type of the caught throwable
Parameters:
caughtThrowable - the caught throwable

get

public static <E extends Throwable> E get()
Type Parameters:
E - the type of the caught throwable
Returns:
Returns the caught throwable. Returns null if there is no throwable caught.


Copyright © 2015. All rights reserved.