|
-
July 20th, 2005, 03:00 PM
#1
How to check Exceptions while running
Hi , i wonder how could i check, lets say that there will be
ArrayIndexOutOfBoundsException when trying indexing my array with too big
index value.
Is it possible to check that if there's ArrayIndexOutOfBoundsException , application continues running without showing that exception but diminishing
indexing value as long as its needed to get out of exception situation.
Thanks.
-
July 20th, 2005, 10:25 PM
#2
Re: How to check Exceptions while running
A RuntimeException like ArrayIndexOutOfBoundsException generally means your code is flawed and has a bug.
Every array has a length field that you can use to check the index against:
Code:
int i = ...;
int[] arr = ....;
if (i >= arr.length) // index out of bounds
However, without knowing the context of your code, we can't really provide a good solution.
Hungarian notation, reinterpreted? http://www.joelonsoftware.com/articles/Wrong.html
-
July 21st, 2005, 09:14 AM
#3
Re: How to check Exceptions while running
Yes, your code is usually flawed if it is possible to get an ArrayIndexOutOfBoundsException. However, if you want to be able to handle this exception, here's how you do it:
Code:
try
{
//Insert Code that throws the exception here
}
catch(ArrayIndexOutOfBoundsException exceptionName)
{
//Insert Code to execute only when the problem occurs
}
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|