framework. The Struts framework, for example, underwent (Java web server) some
framework. The Struts framework, for example, underwent some significant changes to its APIs between Versions 1.0 and 1.1. In particular, the perform( )method is no longer the controller’s preferred method for invoking the Action; instead, it uses the execute( ) method. Fortunately, the developers working on the Struts framework were careful and ensured that the new functionality was compatible with applications built using earlier versions. You should take that same care when building your applications. If, for example, you override methods of the Struts framework to achieve specialized behavior, it’s not out of the realm of possibility that the method will be deprecated or removed in future Struts versions. In fact, several comments in the framework source indicate that certain portions of the Struts framework eventually will be retired. Although it’s nearly impossible to protect your application from all potential changes, it’s best that you go into developing it with your eyes wide open. Using a framework, even one that is as good and as complete as Struts, is not a silver bullet. You will have the same upgrade issues whether you build your own framework or use one provided by another source. Chapter 10. Exception Handling Throwing exceptions is Java’s way of informing dependent clients that something abnormal occurred during the processing of a method. The client is notified of the type of problem by an instance of a specific exception being thrown, and it’s entirely up to the client what course of action to take when an exception occurs. In some cases, the client may even choose not to take any action, which causes the JVM to continue to search for a handler for the exception. Handling exceptions within your Struts applications is not much different. When an abnormal condition occurs, an exception is thrown to the calling client to notify it of the abnormality. What is different for web applications, and specifically the Struts framework, is what action is taken on behalf of the client and how these exceptions are reported back to the end user. This chapter looks at how you can properly use the Java exception-handling mechanism within your Struts applications to help make your applications more robust and allow them to gracefully respond when things do not go as expected. Special attention is given to the differences between performing the exception handling programmatically and using the new declarative feature added to the Struts framework in Version 1.1. 10.1 Java Exception Handling Before we dive into how best to handle exceptions in the Struts framework, you should have a picture in your mind of what actually occurs when a method throws an exception. An understanding of the processes taking place in the JVM when an exception occurs may enlighten you as to the importance of throwing exceptions for the right reason, as well as the importance of throwing the right exceptions. Because there is additional overhead for the JVM to handle an exception, you should always take care to use exceptions correctly. 10.1.1 Java Exceptions In Java, exceptions are objects that are created when an abnormal condition, often referred to as an exception condition, occurs during the execution of an application. When a Java application throws an exception, it creates an object that is a descendant of java.lang.Throwable. The Throwable class has two direct subclasses: java.lang.Errorand java.lang.Exception. Figure 10-1 shows a partial hierarchy tree for the Throwableclass.
If you are in need for chaep and reliable webhost to host your website, our recommendation is http web server services.