Web hosting colocation - 836 Exception Handling Chapter 14 14.11 Provide a
Monday, August 27th, 2007836 Exception Handling Chapter 14 14.11 Provide a single Exception subclass and catch handler for a group of exceptions. As each exception occurs, the exception object can be created with different instance data. The catch handler can examine this data to distinguish the type of the Exception. 14.12 The finally block is the preferred means for preventing resource leaks. 14.13 No, but it does terminate the block in which the Exception is thrown. 14.14 The exception will be processed by a catch handler (if one exists) associated with the try block (if one exists) enclosing the catch handler that caused the exception. 14.15 The reference is removed from memory, and the reference count for the referenced object is decremented. If the reference count is zero, the object is marked for garbage collection. EXERCISES 14.16 Under what circumstances would you use the following catch handler? catch ( Exception exception ) { throw exception; } 14.17 List the benefits of exception handling over conventional means of error processing. 14.18 Describe an object-oriented technique for handling related exceptions. 14.19 Until this chapter, we have found that dealing with errors detected by constructors is a bit awkward. Explain why exception handling is an effective means for dealing with constructor failure. 14.20 Suppose a program throws an exception and the appropriate exception handler begins executing. Now suppose that the exception handler itself throws the same exception. Does this create an infinite recursion? Explain your answer. 14.21 Use inheritance to create an exception superclass and various exception subclasses. Write a program to demonstrate that the catch specifying the superclass catches subclass exceptions. 14.22 Write a Java program that shows that not all finalizers for objects constructed in a block are necessarily called after an exception is thrown from that block. 14.23 Write a Java program that demonstrates how various exceptions are caught with catch ( Exception exception ) 14.24 Write a Java program that shows that the order of exception handlers is important. If you try to catch a superclass exception type before a subclass type, the compiler should generate errors. Explain why these errors occur. 14.25 Write a Java program that shows a constructor passing information about constructor failure to an exception handler after a tryblock. 14.26 Write a Java program that illustrates rethrowing an exception. 14.27 Write a Java program that shows that a method with its own try block does not have to catch every possible error generated within the try. Some exceptions can slip through to, and be handled in, other scopes.
We recommend you use shared web hosting services, because many users agree that it is cheap, reliable and customer-satisfying webhost.