Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

Java question e The method dangerousMethod0 is provided for you by the system. I

ID: 3743047 • Letter: J

Question

Java question e

The method dangerousMethod0 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 dangerousMethodHandlerO from which the dangerousMethodO is called and exceptions are handled. Of special interest to the dangerousMethodHandler) is the illegal argument exception. The dangerousMethodHandler0 prints the stack trace of the error from a StackTraceElement array when an illegal argument exception is caught. For any other types of exceptions, the dangerousMethodHandler0 prints "Exception!". The dangerousMethodHandler) method must not print anything else (including any extra empty ines). Note that dangerousMethod) is a public method that takes no parameters and returns nothing, while dangerousMethodHandler) is a public method that takes no parameters and returns nothing. You may wish to look up the Java API before attempting this question. Note that the expected output is a regular expression (so you don't need to replicate the backslashes, square brackets, ld, Is, In, or +. The sinj+ denote a universal line break, so your output needs to contain a newline instead). For example: Test Result public void javal.lang.Character .toChars CCharacter .java: d+sn]+Main.dangerousMethod(Main.java:Nd dangerousMesinJ+Main.dangerousMethodHandler (Main.java: d+DsIn]+Main.runTests(Main.java: d+) thod sInj+Main.main(Mainl.java:d+) Character.t oChars(-0);

Explanation / Answer

ANSWER :

dangerousMethodHandler() definition :

public void dangerousMethodHandler() {

try {

this.dangerousMethod(); //call to the dangerousMethod()

} catch (IllegalArgumentException e) {

e.printStackTrace();

} catch (Exception e) {

//Exception prited if any other exxception other than Illigal Argument Exception

System.out.println("Exception!");

}

}

Thanks and Give thumps up if the solution is as expected and do comment if any doubts

Hire Me For All Your Tutoring Needs
Integrity-first tutoring: clear explanations, guidance, and feedback.
Drop an Email at
drjack9650@gmail.com
Chat Now And Get Quote