if (catchClause.getOnKeyword() != null) {
// on-catch clause found, verify that the exception type is not a subtype of a previous
// on-catch exception type
TypeName typeName = catchClause.getExceptionType();
if (typeName != null && typeName.getType() != null) {
Type currentType = typeName.getType();
if (currentType.isObject()) {
// Found catch clause clause that has Object as an exception type, this is equivalent to
// having a catch clause that doesn't have an exception type, visit the block, but
// generate an error on any following catch clauses (and don't visit them).
safelyVisit(catchClause);
if (i + 1 != numOfCatchClauses) {
// this catch clause is not the last in the try statement
CatchClause nextCatchClause = catchClauses.get(i + 1);
CatchClause lastCatchClause = catchClauses.get(numOfCatchClauses - 1);
int offset = nextCatchClause.getOffset();
int length = lastCatchClause.getEnd() - offset;
errorReporter.reportErrorForOffset(
HintCode.DEAD_CODE_CATCH_FOLLOWING_CATCH,
offset,
length);
return null;
}
}
for (Type type : visitedTypes) {
if (currentType.isSubtypeOf(type)) {
CatchClause lastCatchClause = catchClauses.get(numOfCatchClauses - 1);
int offset = catchClause.getOffset();
int length = lastCatchClause.getEnd() - offset;
errorReporter.reportErrorForOffset(
HintCode.DEAD_CODE_ON_CATCH_SUBTYPE,
offset,
length,
currentType.getDisplayName(),
type.getDisplayName());
return null;
}
}
visitedTypes.add(currentType);