Common Utility for Exception Searching
Posted
by
Andrew
on Stack Overflow
See other posts from Stack Overflow
or by Andrew
Published on 2011-01-15T04:32:11Z
Indexed on
2011/01/15
4:53 UTC
Read the original article
Hit count: 220
java
|exception-handling
I wrote this little helper method to search the exception chain for a particular exception (either equals or super class). However, this seems like a solution to a common problem, so was thinking it must already exist somewhere, possibly in a library I have already imported. So, any ideas on if/where this might exist?
boolean exceptionSearch(Exception base, Class<?> search) {
Throwable e = base;
do {
if (search.isAssignableFrom(e.getClass())) {
return true;
}
} while ((e = e.getCause()) != null);
return false;
}
© Stack Overflow or respective owner