• 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

Exception Handler for doGet or doPost

 
Ranch Hand
Posts: 61
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Curious about Exception handler for doPost and doGet methods i.e

public void doGet(HttpServletRequest request, HttpServletResponse response)
throws ServletException, IOException {

}

If I call this doGet method using a link in html or jsp and any exception occurs inside
doGet, it will be handled by HttpServlet super class or Container?

thanks.
 
Sheriff
Posts: 67747
173
Mac Mac OS X IntelliJ IDE jQuery TypeScript Java iOS
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
It will not be handled by default and will be propagated out until the error appears in the response sent to the browser.

You should declare an error handler in the deployment descriptor to handle the error as appropriate to your application.
 
Ranch Hand
Posts: 5575
Eclipse IDE Windows XP Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

Bear Bibeault wrote:
You should declare an error handler in the deployment descriptor to handle the error as appropriate to your application.



Hi Bear, i feel, using the try and catch is better than this kind of approach . the deployment descriptor is used for common error handling right?

please correct me
 
Bear Bibeault
Sheriff
Posts: 67747
173
Mac Mac OS X IntelliJ IDE jQuery TypeScript Java iOS
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Why would you pollute each and every servlet with a try/catch block when you can declare it once in the deployment descriptor?
 
Seetharaman Venkatasamy
Ranch Hand
Posts: 5575
Eclipse IDE Windows XP Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Well, Bear suppose you are using a DAO class method [say updateEmployee() which is throws a UserFriendly Exception ] in servlet ,then you need to handle in try catch right ?

Please Correct me,if i am wrong
 
Bartender
Posts: 2856
10
Firefox Browser Fedora Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
The method ( updateEmployee() )will have the try/catch code, most likely. Even if it doesn't have one, error pages come handy. After all, you are not supposed to handle SQLException that was thrown by code written by someone else .

Hope this helps .
 
Seetharaman Venkatasamy
Ranch Hand
Posts: 5575
Eclipse IDE Windows XP Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

Amit Ghorpade wrote:you are not supposed to handle SQLException that was thrown by code written by someone else



Here, i am not talking about the SQLException , A userfriendly exception(logic error)

please clarify the scenario
 
Greenhorn
Posts: 23
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hi, This a sample Example to Handel the error through Deployment Descriptor(web.xml)

<!-- Reporting an error using a JSP page -->

<error-page>

<exception-type>The Exception Class</exception-type>

<location>/error.jsp</location>

</error-page>

Khirod..


 
Khirod Patra
Greenhorn
Posts: 23
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
A user friendly exception(logic error)----->To handle these error,you need to assign the the respective error message(user define or any predefine ) to request object and call to the error page using a condition.

Khirod..


 
Seetharaman Venkatasamy
Ranch Hand
Posts: 5575
Eclipse IDE Windows XP Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Thanks all .
 
Ranch Hand
Posts: 528
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
From try and catch only , you will be propagated to the exceptions defined in the web.XML page
reply
    Bookmark Topic Watch Topic
  • New Topic