compile the program. Other exceptions-those that may be generated at runtime by more unpredictable problems like referencing a null pointer or dividing by zero-don't have to be handled in your program. However, a good programmer will design his or her applet so that common exceptions are handled where appropriate. Review Questions 1. 2. 3. 4. How do you use a try program block? How do you use a catch program block? Do you have to catch all types of exceptions that might be thrown by Java? When a method you call is defined as potentially throwing an exception, do you have to. | compile the program. Other exceptions-those that may be generated at runtime by more unpredictable problems like referencing a null pointer or dividing by zero-don t have to be handled in your program. However a good programmer will design his or her applet so that common exceptions are handled where appropriate. Review Questions 1. How do you use a try program block 2. How do you use a catch program block 3. Do you have to catch all types of exceptions that might be thrown by Java 4. When a method you call is defined as potentially throwing an exception do you have to handle that exception in your program 5. How many exceptions can you associate with a single try block 6. How do you pass an exception up from a called method to the calling method 7. What are the two main types of exceptions that Java may throw Review Exercises 1. Write an applet that creates a button object. Set up exception-handling code for the OutOfMemoryException exception that could possibly occur when Java tries to allocate resources for the button. 2. Write an applet that catches all Exception objects and displays the string returned by the Exception object s getMessage method. Not all Exception objects return message strings. Test your program by generating a divide-by-zero error which will cause Java to throw an ArithmeticException exception. This exception does generate a message string. You can find the solution to this exercise in the CHAP30 folder of this book s CD-ROM. The applet is called ExceptionApplet4. Figure shows what the applet looks like while running under Appletviewer. Figure ExceptionApplet4 displays the message string returned by an Exception object s getMessage method. 3. Write an applet that enables the user to enter values into an array. Use two TextField objects the first being where the user shouldenter the index at which to place the value and the second being the value to add to the array. Set up the applet so that it responds to .