I get why an HttpServlet would throw ServletException, but why IOException? What was the reasoning behind this?
-
If the servlet writes to an output stream (i.e. the page) through I/O interfaces, any I/O error will be reported as an
IOException.Perhaps the API shouldn't be using I/O interfaces directly. It's not uncommon for WebApps using RMI to allow the
RMIExceptionto be fall through the servlet interface (it's a subclass ofIOExceptionfor some reason). -
I'd suggest that an
IOExceptionindicates a problem with processing input/output, e.g. problems reading from the request input, or writing the response, whereas aServletExceptionhas more to do with servlet-specific problems, such as errors regarding servlet provisioning/initialisation, and processing requests. -
From the docs:
IOException - if an input or output error is detected when the servlet handles the GET request
This can happen when you print the servlet output:
response.getWriter().print() - this method throws IOException
The socket can be closed before the response finishes to print the output.
0 comments:
Post a Comment