com.googlecode.junittoolbox.util.TigerThrower Maven / Gradle / Ivy
Go to download
Show more of this group Show more artifacts with this name
Show all versions of junit-toolbox Show documentation
Show all versions of junit-toolbox Show documentation
Useful classes for writing automated tests with JUnit
package com.googlecode.junittoolbox.util;
/**
* This class provides the method {@link #sneakyThrow(Throwable)} which
* enables you to throw any checked {@link Exception} from any method,
* even if its type is not listed in the method signature. Copied from
* Java Puzzlers.
*/
public class TigerThrower {
/**
* Will throw the given {@link Throwable}.
*/
public static void sneakyThrow(Throwable t) {
new TigerThrower().sneakyThrow2(t);
}
private void sneakyThrow2(Throwable t) throws T {
throw (T) t;
}
}