820 Exception Handling Chapter 14 Java s catch-or-declare requirement (Starting a web site)
820 Exception Handling Chapter 14 Java s catch-or-declare requirement demands that the programmer either catcheach checked exception or place it in the throws clause of a method. Of course, placing a checked exception in the throws clause would force other methods to process the checked exception as well. If a programmer feels a particular checked exception is unlikely to occur, the programmer might elect to catch that checked exception and do nothing with it to avoid being forced to deal with it later. This can of course come back to haunt you, because as a program evolves, it may become important to deal with this checked exception. Testing and Debugging Tip 14.6 Do not try to circumvent Java s catch-or-declare requirement by simply catching exceptions and doing nothing with them. Exceptions are generally of a serious enough nature that they need to be processed rather than suppressed. Testing and Debugging Tip 14.7 The Java compiler, through the throws clause used with exception handling, forces programmers to process the exceptions that can be thrown from each method a program calls. This helps avoid bugs that arise in programs when programmers ignore the fact that problems occur and make no provisions for these problems. Software Engineering Observation 14.13 Subclass methods that do not override their corresponding superclass methods exhibit the same exception-handling behavior of the inherited superclass methods. The throws clause of a subclass method that overrides a superclass method may contain the same list of exceptions as the overridden superclass method or a subset of that list. Common Programming Error 14.12 The Java compiler requires that a method either catch any checked exceptions thrown in the method (either directly from the method s body or indirectly through called methods) or declare checked Exceptions the method can throw to other methods; otherwise, the Java compiler issues a syntax error. Testing and Debugging Tip 14.8 Suppose a method throws all subclasses of a particular exception superclass. You may be tempted to list only the superclass in the throws clause. Instead, explicitly list all the subclasses. This focuses the programmer s attention on the specific Exceptions that may occur and will often help avoid bugs caused by performing general processing for a category of exception types. Figure 14.3 Fig. 14.8 list many of Java s Errors and Exceptions hierarchically for the packages java.lang, java.util, java.io, java.awt and java.net. In these tables, a class indented under another class is a subclass. The exception and error classes for the other packages of the Java API can be found in the Java online documentation. The online documentation for each method in the API specifies whether that method throws exceptions and what the exceptions are that can be thrown. We show a portion of Java s Error hierarchy in Fig. 14.3. Most Java programmers ignore Errors. They are serious but rare events. Figure 14.4 is particularly important because it lists many of Java s Runtime- Exceptions. Although Java programmers are not required to declare these exceptions in throws clauses, these are the exceptions that commonly will be caught and handled in Java applications.
We recommend high quality webhost to host and run your jsp application: christian web host services.