The method risky Method () is provided for you by the system, it contains code (
ID: 3838486 • Letter: T
Question
The method risky Method () 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 riskyMethodHandler() from which the riskyMethod() is called and exceptions handled. Of special interest to the riskyMethodHandler() is the null pointer exception. The riskyMethodHandler() returns a string of the exception when a null pointer exception is caught. For any other types of exceptions, the riskyMethodHandler() returns the string "Exception!''. If no exception is caught, the riskyMethodHandler() returns the string "No exception!" Note that riskyMethod() is a public method that takes no parameters and returns nothing, while riskyMethodHandler() is a public method that takes no parameters and returns a string You may wish to look up the Java API before attempting this question. For example: Public void riskyMethod() {string 1 = null; 1. length ();} java. lang. NullPointerExceptionExplanation / Answer
Answer:
public String riskyMethodHandler() {
try{
riskyMethod();
return "No Exceotion";
}
catch(NullPointerException e1){
return e1.toString();
}
catch(Exception e){
return "Exception";
}
}
public void riskyMethod() {
String l = null;
l.length();
}