harmony-dev mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From Richard Liang <richard.lian...@gmail.com>
Subject Re: [classlib] Exception throwing compatibility: java.util.Scanner
Date Fri, 07 Jul 2006 02:09:48 GMT


Geir Magnusson Jr wrote:
> This is a great example.  The last two aren't even legal exceptions for
> that method.
>
> It seems like the RI is doing random crap, and it wouldn't be something
> that someone would depend on... can you imagine?
>
>   
Thanks a lot, Geir. There may be a great deal of these "great examples". 
;-)

This makes our discussion about "Exception throwing compatibility"  more 
complex.

Best regards,
Richard.
> try {
>     Scanner.nextInt(foo);
> }
> catch {StringInxOutOfBndsEx bar) {
>     ... real problem...
> }
> catch (InputMismatchEx woogie) {
>     ... erm, a 1?
> }
> catch (PatternSyntaxException blough) {
>     .. a 0
> }
>
> This is something where I'd suggest we consider doing it per the spec,
> and noting the difference...  I can't even imagine someone depending on
> the IME or PSE to find 1 and 0 respectively...
>
> geir
>
>
> 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.
>>
>> 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
>>        }
>> }
>>
>>     
>
> ---------------------------------------------------------------------
> 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
>
>
>   

-- 
Richard Liang
China Software Development Lab, IBM 


Mime
  • Unnamed multipart/alternative (inline, None, 0 bytes)
View raw message