Allow but ignore multiple exception handlers for the same exception

This commit is contained in:
Ben Gruver 2014-07-21 18:54:30 -07:00 committed by Connor Tumbleson
parent 3d2e935f08
commit 394bb25b7c
2 changed files with 5 additions and 11 deletions

View File

@ -166,7 +166,6 @@ public class TryListBuilder<EH extends ExceptionHandler>
String existingType = existingHandler.getExceptionType();
String newType = handler.getExceptionType();
// Don't add it if we already have a handler of the same type
if (existingType == null) {
if (newType == null) {
if (existingHandler.getHandlerCodeAddress() != handler.getHandlerCodeAddress()) {
@ -176,10 +175,9 @@ public class TryListBuilder<EH extends ExceptionHandler>
return;
}
} else if (existingType.equals(newType)) {
if (existingHandler.getHandlerCodeAddress() != handler.getHandlerCodeAddress()) {
throw new InvalidTryException(
"Multiple overlapping catches for %s with different handlers", existingType);
}
// dalvik doesn't reject cases when there are multiple catches with the same exception
// but different handlers. In practice, the first handler "wins". Since the later
// handler will never be used, we don't add it.
return;
}
}

View File

@ -449,12 +449,8 @@ public class TryListBuilderTest {
TryListBuilder tlb = new TryListBuilder();
tlb.addHandler(5, 10, new ImmutableExceptionHandler("LException1;", 5));
try {
tlb.addHandler(0, 15, new ImmutableExceptionHandler("LException1;", 6));
} catch (TryListBuilder.InvalidTryException ex) {
return;
}
Assert.fail();
// no exception should be thrown...
}
@Test