The method wobblyMethod() is provided for you by the system. It contains code (w
ID: 3838489 • Letter: T
Question
The method wobblyMethod() is provided for you by the system. It contains code (which you can't see here) that is prone to throw a variety of exceptions. Write a method wobblyMethodHandler() from which the wobblyMethod() s called and exceptions handled. Of special interest to wobblyMethodHandler() is the array index out of bounds exception. The wobblyMethodHandler() returns a string "Array index [index number] is out of bounds!" when an array index out of bounds exception is caught. For any other types of exceptions, the wobblyMethodHandler() returns the string "Exception!". If no exception is caught the wobblyMethodHandler() returns "No exception". Note that wobblyMethod() is a public method that takes no parameters and returns nothing, while the wobblyMethodHandler() is a public method that takes no parameters and returns a string.Explanation / Answer
Answer:
public String wobbyMethodHandler() {
try{
wobbyMethod();
return "No Exceotion";
}
catch(ArrayIndexOutOfBoundsException e1){
return "Array index "+e1.getMessage()+" out of bounds";
}
catch(Exception e){
return "Exception";
}
}
public void wobbyMethod() {
int a[]= new int[3];
a[3]=12;
}
Related Questions
Hire Me For All Your Tutoring Needs
Integrity-first tutoring: clear explanations, guidance, and feedback.
Drop an Email at
drjack9650@gmail.com
drjack9650@gmail.com
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.