Results 1 to 3 of 3
Thread: StringIndexOutOfBoundsException
- 01-29-2008, 01:00 PM #1
Senior Member
- Join Date
- Nov 2007
- Posts
- 115
- Rep Power
- 0
StringIndexOutOfBoundsException
Review the code below:
I might get two exceptions here.Java Code:try { arrayList.get(10); } catch (StringIndexOutOfBoundsException e) { ... }
- StringIndexOutOfBoundsException
- IndexOutOfBoundsException
StringIndexOutOfBoundsException is subclass of IndexOutOfBoundsException. So I believe that my catch will catch both Exceptions. Is this right?
- 01-29-2008, 02:21 PM #2
Senior Member
- Join Date
- Jun 2007
- Location
- Bali, Indonesia
- Posts
- 696
- Rep Power
- 6
It should be IndexOutOfBoundsException. But as this exception is a runtime exception it is ok if you don't catch it. The better solution is to check the size of your array list before you try to read data at the speficied index.
Website: Learn Java by Examples
- 01-29-2008, 11:25 PM #3


LinkBack URL
About LinkBacks
Reply With Quote

Bookmarks