Adding Global Exceptions

 < Day Day Up > 



The <global-exceptions> sub-element is used to define n-number of <exception> sub-elements that are throwable by any Action in a Struts application. This sub-element acts as a container for all public <exception> sub-elements.

The <exception> sub-element is used to associate a global exception with an ExceptionHandler. The sub-element is the core piece of the <global-exceptions> definition. The syntax of the <global-exceptions> sub-element, including an example nested <exception> element, is shown here:

 <global-exceptions>   <exception key="Key" type="Exception Type"     handler="Exception Handler"> </global-exceptions> 

Table 15.5 describes the attributes of an <exception> sub-element.

Table 15.5: The Attributes of an <exception> Sub-Element

Attribute

Description

bundle

A ServletContext attribute that names the resource bundle associated with the ExceptionHandler handling the defined <exception> elements. The default attribute is defined by the Globals.MESSAGES_KEY (org.apache.struts.Globals.MESSAGES_KEY). (optional)

className

The fully qualified class name of the configuration bean associated with the defined handler. The default class is org.apache.struts.config.ExceptionConfig.

handler

The fully qualified class name of the ExceptionHandler that will process the contained <exception> sub-elements. The default class is org.apache.struts.action.ExceptionHandler.

key

Used to retrieve the message template associated with this exception. (required)

path

The module-relative path that will act as the target of the ExceptionHandler associated with this exception. (optional)

scope

The scope of the ActionError object coupled with this exception. (optional)

type

The fully qualified class name of the exception defined by this <exception> sub-element. (required)

An example of using the <global-exceptions> sub-element is shown in the following code snippet:

 <global-exceptions>   <exception     key="wrox"     type="ch15.WroxException"     handler="ch15.WroxExceptionHandler"> </global-exceptions> 



 < Day Day Up > 



Professional Jakarta Struts
Professional Jakarta Struts (Programmer to Programmer)
ISBN: 0764544373
EAN: 2147483647
Year: 2003
Pages: 183

flylib.com © 2008-2017.
If you may any questions please contact us: flylib@qtcs.net