Suhai G�bor wrote:
>
> Hi everyone!
>
> 1. Am I thinking right that when I throw a ServletException in the doPost or
> doGet method, it only affects the current request, and not all? I mean,
> other requests can come in and can be handled independently.
Yes. An exception only affects the current thread; other request threads
are unaffected.
> What if I throw
> this exception in the init method? Does my servlet load into the memory and
> can it handle requests?
No. If you throw an exception in the init() method, the servlet
container will not allow requests to be sent to the servlet because the
servlet did not successfully complete the init().
>From the Servlet 2.3 Specification:
"2.3.2.1 Error Conditions on Initialization
"During initialization, the servlet instance can signal that it is not
to be placed into active service by throwing an UnavailableException or
ServletException.If a servlet instance throws an exception of this type,
it must not be placed into active service and the instance must be
immediately released by the servlet container. The destroy method is not
called in this case as initialization was not considered to be
successful."
> 2. In my servlet I use some helper class, which can throw exceptions.
>
> doPost() throws ServletException {
> try {
> handleRequest();
> }
> catch (HandleException he) {
> throw new ServletException();
> }
> }
>
> handleRequest() throws HandleException {
> try {
> getSomethingFromDB();
> }
> catch (DBException dbe) {
> throw new HandleException();
> }
> }
>
> getSomethingFromDB throws DBException
>
> Is it a good practice or I have to forget it and do something else (throw
> RuntimeException in getSomethingFromDB)?
No. I do not consider the above to be good practice. Look at what
happens when an exception is thrown. The exception gets thrown up the
stack until it reaches doPost, which throws the ServletException. The
servlet container catches this exception, so on the server-side there is
no problem. The servlet container does not send a response back when it
catches an exception. On the client side however, the client waits and
waits and never gets a response from the server, until it finally times
out.
In my opinion, your servlet should always send a response back to the
client. You can still throw the exception up to the servlet container if
you want, but you should also send a response back to the client which
says that the request could not be processed.
K Mukhar
___________________________________________________________________________
To unsubscribe, send email to [EMAIL PROTECTED] and include in the body
of the message "signoff SERVLET-INTEREST".
Archives: http://archives.java.sun.com/archives/servlet-interest.html
Resources: http://java.sun.com/products/servlet/external-resources.html
LISTSERV Help: http://www.lsoft.com/manuals/user/user.html