CS 239 - Lab: Experimenting with Exception Handling Name: Answer the questions from the lab in the spaces below. Note, the context for the questions is in the lab assignment instructions. 3.1.c. What was output by the application when you executed it? ----jGRASP exec: java Example1 The answer is: 2 Done. ----jGRASP: operation complete. 3.2.c What "error" was generated by the application when you executed it? Exception in thread "main" java.lang.ArithmeticException: / by zero at Example1.main(Example1.java:10) 3.2.d Why was this "error" generated at run-time (rather than at compile-time)? The compiler does not "know" that denominator's value at the time of the operation is 0. And even if it did, it does not check the logic of the program; it only looks to see that we are not violating any syntactic rules. In this case the division is a valid operation; it uses two integer operands, and the result is assigned to an integer, all of which are valid. 3.3.c What error was generated and why? Example1.java:16: variable ratio might not have been initialized System.out.println("The answer is: "+ratio); ratio is initialized inside of the try block. The try block signifies that there may be a condition that will cause an exception...if so ratio may not get initialized. 3.4.d What output was generated? ----jGRASP exec: java Example1 Done. ----jGRASP: operation complete. 3.5.c What output was generated? ----jGRASP exec: java Example1 java.lang.ArithmeticException: / by zero at Example1.main(Example1.java:12) Done. ----jGRASP: operation complete. 3.5.d Did the application execute properly or not? Yes, when we reached the divide by zero condition, the catch block executed and displayed the error and call stack information. 4.1.c What error was generated? ----jGRASP exec: javac U:\Web\Courses\CS239\labs\L02wa\Example2.java Example2.java:19: variable i might not have been initialized numbers[i]+"/"+numbers[i+1]); ^ 1 error ----jGRASP wedge2: exit code for process is 1. ----jGRASP: operation complete. 4.2.c What error was generated? ----jGRASP exec: javac U:\Web\Courses\CS239\labs\L02wa\Example2.java Example2.java:20: variable i might not have been initialized numbers[i]+"/"+numbers[i+1]); ^ 1 error ----jGRASP wedge2: exit code for process is 1. ----jGRASP: operation complete. 4.2.d It is not possible for "i" to be used before it is initialized. Why is this error generated anyway? (Hint: think about block statements) It's been initialized inside of the scope of the try block. Therefore the compiler is interpreting that the code to initialize i might not be executed, leaving i uninitialized. 4.3.c What output was generated? ----jGRASP exec: java Example2 100/10=10 Couldn't calculate 10/0 ----jGRASP: operation complete. 4.3.d Why aren't all of the divisions attempted? The "for" loop is inside of the try block. When the first exception is generated, control passes to the catch block. When the catch block is executed, processing resumes with the next statement following the catch which is the end of the method. 4.4 Copy your code for 4.4 here 5.2 Copy your code for 5.2 here