wood burning stoves 2.0*
The moose likes Struts and the fly likes Questions about Exception handling Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of OCA/OCP Java SE 7 Programmer I & II Study Guide this week in the OCPJP forum!
JavaRanch » Java Forums » Frameworks » Struts
Bookmark "Questions about Exception handling" Watch "Questions about Exception handling" New topic
Author

Questions about Exception handling

Artemesia Lakener
Ranch Hand

Joined: Jun 21, 2005
Posts: 162
1. what's the difference between <global-exception> and "local exception" (defined inside the <action> tag) ? Doesn't <global-exception> belong to some Actions ? Are they the exceptions that are *not* handled by Action ?

2. For <global-exception> should I always define the scope to "session" ? I guess "scope=request" won't work because it won't carry it all the way down. Right ?

3. If an exception is declared in the struts-config.xml, do I still have to write code like "ActionErrors erros = new ActionError(..); errors.add(new ..)" kind stuff ?

4. Is it true that if an exception IS caught and handled specifically in an Action, then it should *not* be declared in struts-config.xml any more (no matter global or local exception) ?
Kaiser Lautern
Greenhorn

Joined: May 11, 2005
Posts: 18
Far from being an authoritative answer, I'll give only my impressions on this subject. If I am wrong, please anybody correct me.

1) I'd say that an exception declared as global will be caught by Struts independently of which action (or business logic) it was fired in; declared inside an action, only this specific action would treat (pass the control to the handler);

2)scope here is only the context used to look for the ActionError object, and I think we can use request scope in both global and local exceptions.

3) Exceptions have the "key" parameter that you can use to send a message to the view. But you can always use ActionError. Of course that if all you need is to to send messages to the jsp (without any other more elaborate processing) maybe you could get along without exceptions in the first place and use only ActionError (or ActionMessage).

4) this is the "declarative" way of treating exceptions in struts. So it spares you from writing try/catch blocks. So you should choose one way: either declare your exceptions in the struts-config or write explicit code (try/catch) in in your actions.

Hope it helps and please tell me if there is any false reasoning.

Kaiser

Originally posted by Artemesia Lakener:
1. what's the difference between <global-exception> and "local exception" (defined inside the <action> tag) ? Doesn't <global-exception> belong to some Actions ? Are they the exceptions that are *not* handled by Action ?

2. For <global-exception> should I always define the scope to "session" ? I guess "scope=request" won't work because it won't carry it all the way down. Right ?

3. If an exception is declared in the struts-config.xml, do I still have to write code like "ActionErrors erros = new ActionError(..); errors.add(new ..)" kind stuff ?

4. Is it true that if an exception IS caught and handled specifically in an Action, then it should *not* be declared in struts-config.xml any more (no matter global or local exception) ?
David Ulicny
Ranch Hand

Joined: Aug 04, 2004
Posts: 724
Read about
Naming Policy

Kaiser Lautern .

Kaiser is emperor in german? Isn't it?




SCJP<br />SCWCD <br />ICSD(286)<br />MCP 70-216
sudhakar Tadepalli
Ranch Hand

Joined: Dec 27, 2001
Posts: 130
Can any one ponit me to the documentation or example how to use Global and local exceptions declared in struts-config file and how they used in Action or jsp ?


Thanks
Sudhakar
 
With a little knowledge, a cast iron skillet is non-stick and lasts a lifetime.
 
subject: Questions about Exception handling