• Post Reply Bookmark Topic Watch Topic
  • New Topic

Trying to create exception  RSS feed

 
Anonymous Cheeky
Greenhorn
Posts: 1
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I want to throw an IllegalArgumentException for an item out of bounds of the array, however I keep getting an ArrayOutOfBounds exception, although i threw the illegalargument one. I also tried catching. The question is how to override the arrayoutofbounds exception and instead throw an illegalargumentexception ?

Thanks
 
Junilu Lacar
Sheriff
Posts: 11494
180
Android Debian Eclipse IDE IntelliJ IDE Java Linux Mac Spring Ubuntu
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
You're getting an ArrayIndexOutOfBoundsException (AIOOBE) because your program logic is wrong.  If you're going to throw an IllegalArgumentException (IAE), you should make sure that the code you wrote to check for the condition where you would throw an IAE is correct. Since your code throws an AIOOBE instead, this tells you that it's not.
 
Liutauras Vilda
Sheriff
Posts: 4923
334
BSD
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
1. Look for the line numbers (top most, i.e line number 2 from the example below) in the error message you're getting
dummy random example taken from google search wrote:

2. Copy some code (5-10 lines above) from near identified line.
3. Paste it here
3.1. Use code tags
 
Liutauras Vilda
Sheriff
Posts: 4923
334
BSD
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
And welcome the the Ranch.
 
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!