开发者

Manually adding IndexOutOfBounds Exception

I'm trying to manually throw an index out of bounds exception for an array. I know that to throw a regular exception, I can do something like:

if(x>array.length){
throw new Exception("Bad choice!");
}

But how can I do the index out of bounds ex开发者_如何学JAVAception?

Thanks


throw new IndexOutOfBoundsException("Index " + x + " is out of bounds!");

The API is a very good resource. Checking it before posting a question could save you the time of doing so.


You can do:

throw new IndexOutOfBoundsException();


throw new IndexOutOfBoundsException("Index out of bound");

Why is this not working?

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜