I undestand that there are exceptions to the rule. But it's not always the correct case to do either.
I think it comes down to a few things, firstly whether or not you are expecting a higher volume of passes, or fails. You would assume in his case it is normally going to be valid input, so this is an argument for try/catch.
But also the OPs original question does infact state any non numeric characters, which suggests that there will be no input such as (-|.) e.g. characters associated with negative values & floating point numbers.
Also, suggesting the comparison of a large number doesn't really play ball here. Integer.toString()
is going to be limited by the value of Integer.MAX_VALUE
so if you only wish to allow numbers upto that size then it will only have 10 digits to check (at max). On the flip side, if he is wishing to allow numbers to be greater than this, then there could well be meritt to manually checking. But this does depend on how the data is intended to be used, as Long, or BigDecimal may be a better approach.
But I understand that perhaps I am a little over the top inregards to things like this due to the fact I am used to developing on restrained equipment, where by avoid exception is seriously important, and I comply with the fact that an exception is only used in an exceptional case because of this.
Chris