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

View File

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