You can modify, define, handle, and log errors in IBM® WebSphere® Portlet Factory web applications.
The following ways can handle errors in web applications:
- Java Try Catch
- Error Handler builder
A typical way to handle an error is to display an error page to the user. The WebSphere Portlet Factory provides a default error page that is displayed when an unhandled error occurs. You can also create and substitute your own custom error page in place of this default.
Java Try Catch
Error handling for web applications developed with the WebSphere Portlet Factory is similar to error handling in Java development. You can use the Java language Try Catch error handling mechanisms to handle exceptions generated by methods and linked Java objects included in your application. You specify an action to try and if that action fails, you specify an action to catch and process the error.
Error Handler builder
To catch and handle an exception (error) in a model or an action, you can place an Error Handler builder in the model and assign it to an action. When you place this builder in a model, you specify:
This is the action you want the builder to monitor. For example, such an action might be the loading of a particular page.Catch Action
This is the action you want the builder to initiate if an exception occurs. For example, you might want to invoke a method or display a specific error-related page.
The difference with error handling in the WebSphere Portlet Factory is that an Error Handler builder call specifies the try and catch actions, instead of an individual action specifying its own try catch actions.
You can monitor exceptions at various levels. You can assign as the try action a page action, a method action, or an individual action in an action list. In addition, you can enable the builder to catch and handle all unhandled exceptions in a model. This approach ensures that any unexpected error is caught and handled.
You can place multiple Error Handler builders in a model. To work with a specific type of exception in a method, you can specify an exception class in the Error Handler builder. (The indirect reference widget for this builder input allows you to select a Java class in your project.) Thus you can assign multiple Error Handler builders to multiple exceptions on the same method or model.
Testing an error handler
The easiest way to test the error handler is to force an error explicitly.
Parent topic: Developing Web applications with IBM WebSphere Portlet Factory