Overview: Handling errors
In this topic ...
Advanced Error Handling Techniques
Related Topics ...
How do I... Handle Errors and Exceptions?
Example: Catching a Timeout Exception
How to Use the Error Handler Builder
There are several ways we can handle errors and exceptions generated by an application. The Factory contains a special Builder -- Error Handler -- we can use to catch and handle exceptions in a model. In addition we can use the Java language s Try/Catch error handling mechanisms to handle exceptions generated by Methods and Linked Java Objects included in your application.
We can place an Error Handler Builder in a model and specify as builder inputs "try" and "catch" actions. When an exception occurs, the Builder will catch it and handle it according to your instructions.
A typical way to handle an error is to display an error page to the user. The Factory provides a default error page that is displayed when an un-handled error occurs. We can also create and substitute your own custom error page in place of this default.
An Error Handler Builder can be assigned to a variety of model actions including: page actions, individual actions in an Action List, and methods. In addition, we can enable the builder to catch and handle all un-handled exceptions in a model. This "catch-all" approach ensures that any unexpected error is caught and handled.
Advanced Error Handling Techniques
If the method calls within the Java-based method have an error handler, the lower-level handler, which is the handler in the method calls contained in the Java-based method, is called. To pass the handler up to a higher-level, the handler must re-throw the exception.
The action called to handle the error has access to the original exception through an attribute on the request object. This allows access to the exception information from a method or a JSP page.
For example, in a method that was specified to handle an error we can find the exception by using the following code:
HttpServletRequest request = webAppAccess.getHttpServletRequest();
Throwable ex = (Throwable)request.getAttribute("bowstreet.errorhandler.Exception");
String actionName = (String)request.getAttribute("bowstreet.errorhandler.ActionName");
When adding the Error Handler Builder to a specified action, be careful to associate the error handler with the action at which you want processing to stop upon failure.
For example, assume you added to a model an Action List builder call (main) containing two actions with the first one a method (MyMethod) and the second action a page (MyPage). If you type MyMethod in the Try Action field and an exception occurs in that action, the error handler is called. If your error handler does a normal return, MyPage page is still called, instead of stopping the processing, as shown below:
To stop the processing when the exception is called, type Main in the Try Action field. This technique places the handler on the main Action List builder call, containing MyMethod and MyPage. This technique stops the processing of the action on an exception.
Handling Data Entry Validation Errors
A "Data Entry" page is a page which is managed by the Data Page Builder. On a Data Entry page, any of the fields can be set to Data Entry. There are a variety of techniques we can use to deal with errors a user makes when entering data in such a page. These techniques are beyond the scope of the Error Handler builder, however,. For additional error handling techniques related specifically to the Data Page builder, review Techniques for Data Entry Validation. This topic discusses a variety of ways we can trap and respond to data input errors on a data entry page created by the Data Page builder.