Re:FastDoubleParser: Java port of Daniel Lemires fast_double...
by muzster on Tuesday March 23, 2021 @04:56AM
(#26552628)
Agreed. Though catching and handling that exception maybe more performant if majority of those indexes are within the bounds of the array.
>> I'm not sure why having the separate exception is better than letting the array access throw directly?
(1) The original String charAt method (Sun/Oracle) had to account for an offset and an index. The exception from the bounds check on the underlying char[] would be misleading/confusing... and therefore the birth of the seperate StringIndexOutOfBoundsException
Source: http://www.docjar.com/html/api/java/lang/String.java.html
(2) Because of the above and for backward compatibility, the OpenJDK is doing the same exception handling... sometimes it pays to review the original source code to get some context and rationale to the OpenJDK version.
The source of charAt is also interesting because it manually bounds checks while the array access into the underlying char[] has its own bounds check. I'm not sure why having the separate exception is better than letting the array access throw directly?
https://github.com/AdoptOpenJDK/openjdk-jdk11/blob/19fb8f93c...