I'm writing a method that will return true if exception is instance of *someClass*. But I can't import one of the classes because it is in another module. I can't add that module to the project, so I guess, I cant use instanceof.
I consider creating a Map of Strings - exception's classnames and check if my exception's classname is in the map, but I think it would be rather slow and ugly.
Method looks like:
public boolean checkExceptionClass(Throwable cause){
return (cause instanceof firstException
|| cause instanceof secondException
|| cause instanceof iDontHaveThatClassException // can't do that
|| cause instanceof fourthException);
}
Maybe I don't see good solution to that problem right under my nose. Any ideas and advices are much appreciated.
Throwable. I found that it is present in logs so I need to filter it.cause instanceof IsLogged. It removes the magic of checking for (foreign) class names.