Skip to content

Commit 781ad31

Browse files
committed
avoid throwing exceptions across boundary in StringBuiltins.get
1 parent 7963254 commit 781ad31

File tree

1 file changed

+5
-6
lines changed
  • graalpython/com.oracle.graal.python/src/com/oracle/graal/python/builtins/objects/str

1 file changed

+5
-6
lines changed

graalpython/com.oracle.graal.python/src/com/oracle/graal/python/builtins/objects/str/StringBuiltins.java

Lines changed: 5 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -2355,14 +2355,13 @@ public String doString(VirtualFrame frame, Object primary, Object idx,
23552355
} else {
23562356
index = lib.asSize(idx);
23572357
}
2358-
try {
2359-
if (index < 0) {
2360-
index += str.length();
2361-
}
2362-
return charAtToString(str, index);
2363-
} catch (StringIndexOutOfBoundsException | ArithmeticException e) {
2358+
if (index < 0) {
2359+
index += str.length();
2360+
}
2361+
if (index < 0 || index >= str.length()) {
23642362
throw raise(IndexError, ErrorMessages.STRING_INDEX_OUT_OF_RANGE);
23652363
}
2364+
return charAtToString(str, index);
23662365
}
23672366

23682367
@SuppressWarnings("unused")

0 commit comments

Comments
 (0)