C
Chris Smith
Pedro said:The following code snippet fails with an ArrayIndexOutOfBoundsException
char[] msg = {'m', 'o', 'o', 'b'};
for(int i = msg.length - 1; i < msg.length; i--)
{
System.out.print(msg);
}
The code is obviously broken. I don't understand why you'd ever expect
it *not* to fail with an exception. It's pointless to try and
anticipate all possible bugs in code and write code to detect them and
prevent exceptions. It's better for the code above to fail with the
IndexOutOfBoundsException and thus let the programmer know that
something is seriously wrong during testing.
After all, if you detected that something is wrong in your own code,
what would you do? The best choice is probably to throw an exception,
but that raises the question of why you write the test code in the first
place.
--
www.designacourse.com
The Easiest Way to Train Anyone... Anywhere.
Chris Smith - Lead Software Developer/Technical Trainer
MindIQ Corporation