Integer.parseInt () already throws a NumberFormatException. In your example, it seems more appropriate to throw an IllegalArgumentException:
int minMonth = 0; int maxMonth = 11; try { intmm = Integer.parseInt(mm); if (intmm < minMonth || intmm > maxMonth) { throw new IllegalArgumentException (String.format("The month '%d' is outside %d-%d range.",intmm,minMonth,maxMonth)); } } catch (NumberFormatException nfe) { throw new IllegalArgumentException (String.format("The month '%s'is invalid.",mm) nfe); }
source share