I tried to write some kind of exception handler for my specific purposes. I have a list of classes. Let's say:
List<Class<? extends Throwable>> list = new LinkedList<>();
list.add(RuntimeException.class);
list.add(IllegalArgumentException.class);
Now, I want to do:
public Class<? extends Throwable> findMostSpecific(Class<? extends Throwable> type) {
for (....) {
if (... WHAT TO PUT HERE ? .... ) {
return ....
}
}
}
this method has to find the most specific class of given type. So if I pass:
- IllegalArgumentException, it has to find IllegalArgumentException (not RTE).
- RuntimeException, it has to find RuntimeException
- IllegalStateException, it has to find also RuntimeException (becuse IllegalStateException is not on the list)
- if I add
CustomException extends IllegalArgumentExceptionand pass it, it has to return IllegalArgumentException (not RTE and CustomException is not on the list, so IllegalArgumentException is the most specific)
So how to find the most specific type of a given instance? Is it possible?