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
MyCustomException
Why would you want to avoid getCause. You can, of course, write yourself a method to perform the task, something like:
getCause
public static boolean isCause( Class extends Throwable> expected, Throwable exc ) { return expected.isInstance(exc) || ( exc != null && isCause(expected, exc.getCause()) ); }