I am writing some JUnit tests that verify that an exception of type MyCustomException
is thrown. However, this exception is wrapped in other exceptions a number of
Well, I think there's no way to do this without calling getCause()
. It you think it's ugly implement a utility class for doing this:
public class ExceptionUtils {
public static boolean wasCausedBy(Throwable e, Class extends Throwable>) {
// call getCause() until it returns null or finds the exception
}
}