[3025] in java-interest

home help back first fref pref prev next nref lref last post

Re: String.substring lies about what exceptions is throws

daemon@ATHENA.MIT.EDU (Arthur van Hoff)
Thu Oct 26 23:39:40 1995

Date: Thu, 26 Oct 1995 18:43:50 -0700
From: Arthur.Vanhoff@Eng.Sun.COM (Arthur van Hoff)
To: jpayne@starwave.com
Cc: java-interest@java.Eng.Sun.COM


Hi Jon,

>     public String substring(int beginIndex, int endIndex) {
> 	if (beginIndex > endIndex) {
> 	    int tmp = beginIndex;
> 	    beginIndex = endIndex;
> 	    endIndex = tmp;
> 	}
> 	if (beginIndex < 0) {
> 	    throw new StringIndexOutOfBoundsException(beginIndex);
> 	} 
> 	if (endIndex > count) {
> 	    throw new StringIndexOutOfBoundsException(endIndex);
> 	}
> 	return ((beginIndex == 0) && (endIndex == count)) ? this :
> 		   new String(value, offset + beginIndex, endIndex - beginIndex);
>     }
> 
> It doesn't declare it's throwing any exceptions ...  Was the prebeta
> release compiled with the prebeta compiler?  I think not.

You don't have to declare RuntimeExceptions. StringIndexOutOfBoundsException is
a subclass of RuntimeException.

Have fun,

	Arthur van Hoff
-
This message was sent to the java-interest mailing list
Info: send 'help' to java-interest-request@java.sun.com

home help back first fref pref prev next nref lref last post