Win a copy of Five Lines of Code this week in the OO, Patterns, UML and Refactoring forum!
  • 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 all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Bear Bibeault
  • Ron McLeod
  • Jeanne Boyarsky
  • Paul Clapham
Sheriffs:
  • Tim Cooke
  • Liutauras Vilda
  • Junilu Lacar
Saloon Keepers:
  • Tim Moores
  • Stephan van Hulst
  • Tim Holloway
  • fred rosenberger
  • salvin francis
Bartenders:
  • Piet Souris
  • Frits Walraven
  • Carey Brown

execute() and exception handling

 
Ranch Hand
Posts: 56
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi,
I have a question.
I haver a class which extends from Struts Action class.
The execute method has been overridden as below.
What will happen if I throw an application exception from the
execute().How struts will display or treat the application exceptions thrown from execute().
I don't have the applicationexception declared in the struts-config.xml.

Thanks in advance,

Please see my code snippet below.

public ActionForward execute (ActionMapping mapping,
ActionForm form,HttpServletRequest request,
HttpServletResponse response) throws Exception
{
//perform database operation
int i = new DAO().getId();
if(i == 9)
throw new DataInvalidException("Data is invalid");

}
 
Ranch Hand
Posts: 4864
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
In this case, Struts will send an error code 500 back to the browser, along with an ugly error message. If you don't catch an exception in your Execute() method, you should definitely register the exception as a global exception in your struts-config.xml. That way you have control over what gets displayed when the exception occurs.
 
I've read about this kind of thing at the checkout counter. That's where I met this tiny ad:
Building a Better World in your Backyard by Paul Wheaton and Shawn Klassen-Koop
https://coderanch.com/wiki/718759/books/Building-World-Backyard-Paul-Wheaton
    Bookmark Topic Watch Topic
  • New Topic