harmony-dev mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From Paulex Yang <paulex.y...@gmail.com>
Subject Re: [classlib] Exception throwing compatibility: java.util.Scanner
Date Thu, 06 Jul 2006 13:44:09 GMT
Richard Liang wrote:
> Hello All,
>
> When I'm trying to implement Scanner.nextInt(int radix), I met a problem.
>
> As we all know, Character.MIN_RADIX equals 2 and Character.MAX_RADIX 
> equals 36, so the parameter radix can not less than 2 or greater than 
> 36, Otherwise that parameter is illegal.
>
> But on RI, when the parameter radix is illegal, there are different 
> kinds of Exception thrown.
>
>    * If the parameter is less than 0 or greater than 36, RI throws a
>      StringIndexOutOfBoundsException. Obviously this exception depends
>      an RI's implementation.
>    * If the parameter equals 1, RI throws an InputMismatchException
>      with an additional information "The radix 1 is less than the
>      Character.MIN_RADIX".
>    * If the parameter equals 0, RI throws a
>      java.util.regex.PatternSyntaxException whose constructor has three
>      parameters. And the parameters depends on RI's implementation,
>      that makes me can not follow RI.
Is this exception thrown by RegEx class? Should we identify at first if 
our regular expression has different behavior with RI on some certain 
input parameter?
>
> And nothing is documented in the spec. Shall I follow RI's behavior? 
> Thanks a lot.
>
> Here is the test case to demo this issue.
>
> public void test_nextIntI(){
>       Scanner s = new Scanner("123 456");
>
>       try {
>            s.nextInt(-1);
>            fail("Should throw StringIndexOutOfBoundsException");
>        } catch (StringIndexOutOfBoundsException e) {
>            // Expected
>        }
>        try {
>            s.nextInt(0);
>            fail("Should throw PatternSyntaxException");
>        } catch (PatternSyntaxException e) {
>            // Expected
>        }
>        try {
>            s.nextInt(1);
>            fail("Should throw InputMismatchException");
>        } catch (InputMismatchException e) {
>            // Expected
>        }
>        try {
>            s.nextInt(40);
>            fail("Should throw StringIndexOutOfBoundsException");
>        } catch (StringIndexOutOfBoundsException e) {
>            // Expected
>        }
> }
>


-- 
Paulex Yang
China Software Development Lab
IBM



---------------------------------------------------------------------
Terms of use : http://incubator.apache.org/harmony/mailing.html
To unsubscribe, e-mail: harmony-dev-unsubscribe@incubator.apache.org
For additional commands, e-mail: harmony-dev-help@incubator.apache.org


Mime
View raw message