From d679e9bfbced34bcfc054fe7578b6cc1985f1f58 Mon Sep 17 00:00:00 2001 From: Morten Haraldsen Date: Tue, 30 Jan 2024 15:43:15 +0100 Subject: [PATCH] Use exception instead of check --- .../time/internal/LimitedCharArrayIntegerUtil.java | 14 ++++++++------ 1 file changed, 8 insertions(+), 6 deletions(-) diff --git a/src/main/java/com/ethlo/time/internal/LimitedCharArrayIntegerUtil.java b/src/main/java/com/ethlo/time/internal/LimitedCharArrayIntegerUtil.java index 80f3c05..18cd9d2 100644 --- a/src/main/java/com/ethlo/time/internal/LimitedCharArrayIntegerUtil.java +++ b/src/main/java/com/ethlo/time/internal/LimitedCharArrayIntegerUtil.java @@ -50,9 +50,10 @@ private LimitedCharArrayIntegerUtil() public static int parsePositiveInt(final String strNum, int startInclusive, int endExclusive) { int result = 0; - for (int i = startInclusive; i < endExclusive; i++) + try { - try + + for (int i = startInclusive; i < endExclusive; i++) { final char c = strNum.charAt(i); if (c < ZERO || c > DIGIT_9) @@ -61,11 +62,12 @@ public static int parsePositiveInt(final String strNum, int startInclusive, int } result = result * 10 + (c - ZERO); } - catch (StringIndexOutOfBoundsException exc) - { - ErrorUtil.raiseUnexpectedEndOfText(strNum, startInclusive); - } } + catch (StringIndexOutOfBoundsException exc) + { + ErrorUtil.raiseUnexpectedEndOfText(strNum, startInclusive); + } + return result; }