From db8e552ebede2c5706c59fcc0a021f206b4e088e Mon Sep 17 00:00:00 2001 From: Robert von Burg Date: Thu, 12 Mar 2020 10:12:46 +0100 Subject: [PATCH] [New] Added ExceptionHelper.hasCause() --- .../strolch/utils/helper/ExceptionHelper.java | 19 +++++++++++++++++++ 1 file changed, 19 insertions(+) diff --git a/li.strolch.utils/src/main/java/li/strolch/utils/helper/ExceptionHelper.java b/li.strolch.utils/src/main/java/li/strolch/utils/helper/ExceptionHelper.java index 7ffc0bb1b..d073eb9dc 100644 --- a/li.strolch.utils/src/main/java/li/strolch/utils/helper/ExceptionHelper.java +++ b/li.strolch.utils/src/main/java/li/strolch/utils/helper/ExceptionHelper.java @@ -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 causeType) { + Throwable t = throwable; + while (t != null) { + if (t.getClass() == causeType) + return true; + t = t.getCause(); + } + + return false; + } }