Question: On page 368 of Big Java: Late Objects, complete the review exercises: R7.6 What is the difference between throwing an exception and catching an exception?

On page 368 of Big Java: Late Objects, complete the review exercises:

R7.6 What is the difference between throwing an exception and catching an exception?

R7.7 What is a checked exception? What is an unchecked exception? Give an example for each. Which exceptions do you need to declare with the throws reserved word?

R7.8 Why dont you need to declare that your method might throw an IndexOutOfBoundsException?

R7.9 When your program executes a throw statement, which statement is executed next?

R7.10 What happens if an exception does not have a matching catch clause?

R7.11 What can your program do with the exception object that a catch clause receives?

R7.12 Is the type of the exception object always the same as the type declared in the catch clause that catches it? If not, why not?

R7.13 What is the purpose of the try-with-resources statement? Give an example of how it can be used.

R7.14 What happens when an exception is thrown, a try-with-resources statement calls close, and that call throws an exception of a different kind than the original one? Which one is caught by a surrounding catch clause? Write a sample program to try it out.

R7.15 Which exceptions can the next and nextInt methods of the Scanner class throw? Are they checked exceptions or unchecked exceptions?

R7.16 Suppose the program in Section 7.5 reads a file containing the following values: 1 2 3 4 What is the outcome? How could the program be improved to give a more accurate error report?

R7.17 Can the readFile method in Section 7.5 throw a NullPointerException? If so, how?

R7.18 The following code tries to close the writer without using a try-with-resources statement:

PrintWriter out = new PrintWriter(filename); try { Write output. out.close(); } catch (IOException exception) { out.close(); }

What is the disadvantage of this approach? (Hint: What happens when the PrintWriter constructor or the close method throws an exception?)

Step by Step Solution

There are 3 Steps involved in it

1 Expert Approved Answer
Step: 1 Unlock blur-text-image
Question Has Been Solved by an Expert!

Get step-by-step solutions from verified subject matter experts

Step: 2 Unlock
Step: 3 Unlock

Students Have Also Explored These Related Databases Questions!