• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
Bartenders:
  • Mikalai Zaikin

Questions about Exception handling

 
Ranch Hand
Posts: 162
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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) ?
 
Greenhorn
Posts: 18
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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) ?

 
Ranch Hand
Posts: 724
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Read about
Naming Policy

Kaiser Lautern .

Kaiser is emperor in german? Isn't it?


 
Ranch Hand
Posts: 130
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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.
reply
    Bookmark Topic Watch Topic
  • New Topic