[New] Added ExceptionHelper.hasCause()

This commit is contained in:
Robert von Burg 2020-03-12 10:12:46 +01:00
parent 0fe0b3d6c4
commit db8e552ebe
1 changed files with 19 additions and 0 deletions

View File

@ -206,4 +206,23 @@ public class ExceptionHelper {
return t;
}
/**
* Walks the causes for the given {@link Throwable} and sees if the given cause exists
*
* @param throwable
* the {@link Throwable} for which to find the given cause type
*
* @return true if the cause was found, false if not
*/
public static boolean hasCause(Throwable throwable, Class<? extends Throwable> causeType) {
Throwable t = throwable;
while (t != null) {
if (t.getClass() == causeType)
return true;
t = t.getCause();
}
return false;
}
}