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

Java question The method dangerousMethod() is provided for you by the system. It

ID: 3836721 • Letter: J

Question

Java question

The method dangerousMethod() 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 dangerousMethodHandler() from which the dangerousMethod() is called and exceptions are handled. Of special interest to the dangerousMethodHandler() is the illegal argument exception. The dangerousMethodHandler() 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 dangerousMethodHandler() prints "Exception!". The dangerousMethodHandler() method must not print anything else (including any extra empty lines). 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, d, s, , or +. The [s ]+ denote a universal line break, so your output needs to contain a newline instead).

Explanation / Answer

void dangerousMethodHandler() {
      try {
dangerousMethod(); // calling dangerousMethod();
      } catch (IllegalArgumentException e) { //checking Illegal Argument Exception
         System.out.println(e.printStackTrace());
      } catch (Exception e) { // catching any other execption
         System.out.println("Exception ! ");
      }
   }

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