public void readData() {
boolean dataNotFound = true;
if (dataNotFound) {
throw new
IOException();
}
catch(IOException e) {
System.out.println("data
file can't be found");
}
}
a. |
Place the if statement within a try block. |
b. |
Add a throws clause to the method declaration. |
c. |
Set dataNotFound to false. |
d. |
No modification is needed. |
a) Place the if statement within a try block. Explanation: ------------- this method has a catch block. so, there must be a try block preceding it. so, we need to put entire if block inside a try block Fixed code: ------------ public void readData() { boolean dataNotFound = true; try { if (dataNotFound) { throw new IOException(); } } catch (IOException e) { System.out.println("data file can't be found"); } }
Get Answers For Free
Most questions answered within 1 hours.