File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
The moose likes Servlets and the fly likes Throwing Customised Exception from Servlet (JRUN) Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Java » Servlets
Bookmark "Throwing Customised Exception from Servlet (JRUN)" Watch "Throwing Customised Exception from Servlet (JRUN)" New topic

Throwing Customised Exception from Servlet (JRUN)

Sarath Mohan
Ranch Hand

Joined: Mar 17, 2001
Posts: 213
I want to display a customized Exception message from JRun Server whenever an exception occurs. I don't want to print the printStack on browser window.
throw new ServletException(msg) prints stackTrace.
I created my own Exception Class which extends the ServletException.
Then i coded
throw new MyException(msg) still it prints stackTrace.
Please share your ideas

Sarath Mohan
Mike Curwen
Ranch Hand

Joined: Feb 20, 2001
Posts: 3695

What you'd need to do is catch the exception, customized or not, and do not let your Servlet emit this exception. Because you are not actually letting the Exception make it to the servlet runner (in your case JRun), it doesn't produce one of those standardized error pages.

When you catch the exception, place the exception into the attribute space, and redirect (or forward, whichever makes more sense), to an error page.

This way, it looks 'normal' to the servlet runner, and on your error page, you have the choice of displaying the stack trace in white writing on a white background, or as an HTML comment, or not at all.
Sarath Mohan
Ranch Hand

Joined: Mar 17, 2001
Posts: 213
Thanks Mike a lot
Got it
I agree. Here's the link:
subject: Throwing Customised Exception from Servlet (JRUN)
It's not a secret anymore!