}
// the goal is to find the exception with the same/closet inheritance level as the target exception being thrown
int targetLevel = getInheritanceLevel(exception.getClass());
// candidate is the best candidate found so far to return
ExceptionType candidate = null;
// difference in inheritance level between the current candidate and the thrown exception (target level)
int candidateDiff = Integer.MAX_VALUE;
// loop through all the entries and find the best candidates to use
Set<Map.Entry<Class, ExceptionType>> entries = exceptionPolicices.entrySet();
for (Map.Entry<Class, ExceptionType> entry : entries) {
Class clazz = entry.getKey();
ExceptionType type = entry.getValue();
// must be instance of check to ensure that the clazz is one type of the thrown exception
if (clazz.isInstance(exception)) {
// exact match