Explanatory Question
What is wrong with this fragment?
Read the answer carefully and go through the related questions on the right side to improve your understanding of this topic.
// • • • vals[18] = 10; catch (ArrayIndexOutOfBoundsException exc) { // handle error }
The error is that there is no try block before the catch statement.
A catch block must follow a try block, otherwise the compiler will throw an error.
The corrected code should be:
First read the answer fully, then try to explain it in your own words. After that, open a few related questions and compare the concepts. This method helps you remember the topic for a longer time and improves exam preparation.