Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,9 @@ public SCatch(Location location, String type, String name, SBlock block) {

@Override
void storeSettings(CompilerSettings settings) {
block.storeSettings(settings);
if (block != null) {
block.storeSettings(settings);
}
}

@Override
Expand Down Expand Up @@ -115,7 +117,7 @@ void write(MethodWriter writer, Globals globals) {

writer.visitTryCatchBlock(begin, end, jump, MethodWriter.getType(variable.clazz).getInternalName());

if (exception != null && !block.allEscape) {
if (exception != null && (block == null || !block.allEscape)) {
writer.goTo(exception);
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -55,4 +55,47 @@ public void testNoCatch() {
});
assertEquals("test", exception.getMessage());
}

public void testNoCatchBlock() {
assertEquals(0, exec("try { return Integer.parseInt('f') } catch (NumberFormatException nfe) {} return 0;"));

assertEquals(0, exec("try { return Integer.parseInt('f') } " +
"catch (NumberFormatException nfe) {}" +
"catch (Exception e) {}" +
" return 0;"));

assertEquals(0, exec("try { throw new IllegalArgumentException('test') } " +
"catch (NumberFormatException nfe) {}" +
"catch (Exception e) {}" +
" return 0;"));

assertEquals(0, exec("try { throw new IllegalArgumentException('test') } " +
"catch (NumberFormatException nfe) {}" +
"catch (IllegalArgumentException iae) {}" +
"catch (Exception e) {}" +
" return 0;"));
}

public void testMultiCatch() {
assertEquals(1, exec(
"try { return Integer.parseInt('f') } " +
"catch (NumberFormatException nfe) {return 1;} " +
"catch (ArrayIndexOutOfBoundsException aioobe) {return 2;} " +
"catch (Exception e) {return 3;}"
));

assertEquals(2, exec(
"try { return new int[] {}[0] } " +
"catch (NumberFormatException nfe) {return 1;} " +
"catch (ArrayIndexOutOfBoundsException aioobe) {return 2;} " +
"catch (Exception e) {return 3;}"
));

assertEquals(3, exec(
"try { throw new IllegalArgumentException('test'); } " +
"catch (NumberFormatException nfe) {return 1;} " +
"catch (ArrayIndexOutOfBoundsException aioobe) {return 2;} " +
"catch (Exception e) {return 3;}"
));
}
}