Portlet Factory, Version 6.1.2
Handling errors in linked Java object (LJO) methods
You can handle errors in LJO methods using the standard try/catch" mechanism. In the "catch" code, you extract the error information that the IBM® WebSphere Portlet Factory servlet stores in the request. Once you process the error information, you can perform one or more actions to allow processing to proceed or you can simply return an error page.
For example, if the method tries to open a file and fails because the file does not exist, the catch actions could store the error in a variable to be used to supply an error message and display a page in which the user can name another file to open. Unhandled, a file not found error results in the application stopping and the display of the default unhandled error page.
The following code sample shows a method that tries to open a file, and if it is not found, stores the error message in a variable and displays a Specify New File page:
catch (IOException ioe) { HttpServletRequest request = webAppAccess.getHttpServletRequest(); Throwable ex = (Throwable)request.getAttribute("bowstreet.errorhandler.Exception"); StString errorMessage = ex.toString() + " occurred in: " + actionName; ring actionName = (String)request.getAttribute("bowstreet.errorhandler.ActionName"); //log the error webAppAccess.logError(actionName, ex); //set a the value of a variable to the error message webAppAccess.getVariables().setString("ErrorVariable", errorMessage); //display a page prompting for new information webAppAccess.processPage("ErrorPage"); }Parent topic: About error handling in web applications
Library | Support |