• 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
  • Paul Clapham
  • Ron McLeod
  • Jeanne Boyarsky
  • Tim Cooke
Sheriffs:
  • Liutauras Vilda
  • paul wheaton
  • Henry Wong
Saloon Keepers:
  • Tim Moores
  • Tim Holloway
  • Stephan van Hulst
  • Carey Brown
  • Frits Walraven
Bartenders:
  • Piet Souris
  • Himai Minh

Exception handling

 
Ranch Hand
Posts: 34
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hi,
Can somebody help me in soluting the following problem?
I builded my own exception that was extended from RuntimeException, and setup the error-page element in web.xml to redirect the handling of exception to a servlet that handle all exceptions. But the servlet container ignored the setting in web.xml, and tried to find the exception class. How can I solute this problem?
Thanks,
Raymond
 
slicker
Posts: 1108
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
What exactly is your error? If it says it can't find the Exception you created, then it may be failing before it gets to redirect to your error page. When I tested this feature I used SQLException and IOException and forced those to be thrown. Try doing this and then replacing the 'throw new SQLException("my test")' call with your new exception's call. It may shed some light on what is happening.
 
Raymond Ou
Ranch Hand
Posts: 34
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Thanks John,
I wrote the my own exception class and placed it in the classpath, the container can handle the exception by this class.
What I am trying to do is to write a error handler to handle all the exception, like this:
import java.io.*;
import java.sql.*;
import javax.servlet.*;
import javax.servlet.http.*;
import MyException.*;
public class BusinessLogicExceptionHandlerServlet extends HttpServlet
{

public void service(HttpServletRequest request, HttpServletResponse response) throws IOException
{
PrintWriter pw=response.getWriter();
pw.println("<html>");
pw.println("<head>");
pw.println("</head>");
pw.println("<body>");
Throwable exception=(Throwable) request.getAttribute("javax.servlet.error.exception");
if (exception instanceof InsufficientFundsException_Declarative){
pw.println("Sorry, you do not have enough fund.<br>");
}
pw.println("</body>");
pw.println("</html>");
}
};
InsufficientFundsException_Declarative is my own exception, it is a runtime exception.
And the following is set in web.xml:
<error-page>
<exception-type>InsufficientFundsException_Declarative</exception-type>
<location>/servlet/BusinessLogicExceptionHandlerServlet</location>
</error-page>
The problem is when I throw InsufficientFundsException_Declarative exception, the container try to locate this exception class, instead of BusinessLogicExceptionHandlerServlet.
 
Author and all-around good cowpoke
Posts: 13078
6
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

I wrote the my own exception class and placed it in the classpath, the container can handle the exception by this class.


Some servers such as Tomcat 4 ignore your environment classpath and do their own thing so you will have to place the class where the server can see it. If you are using Tomcat, read the Class Loader How-To.
Bill
 
Raymond Ou
Ranch Hand
Posts: 34
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
I will take a look, thanks, Bill.
Your website is cool.
 
I've read about this kind of thing at the checkout counter. That's where I met this tiny ad:
free, earth-friendly heat - a kickstarter for putting coin in your pocket while saving the earth
https://coderanch.com/t/751654/free-earth-friendly-heat-kickstarter
reply
    Bookmark Topic Watch Topic
  • New Topic