✏️ Explanatory Question

What is wrong with this fragment?

👁 34 Views
📘 Detailed Answer
🟢 Easy
💡

Answer with Explanation


// • • •
vals[18] = 10;
catch (ArrayIndexOutOfBoundsException exc) {
    // handle error
}

Solution:

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: