Page 1 of 1

About Question enthuware.jwpv6.2.739 :

Posted: Sat May 14, 2016 7:47 pm
by himaiMinh
For the 4th option, "catch the exception, wrap into ServletException and define the ServletException to error-page mapping in web.xml.
This can be done, even though it is not the best way to handle exception.

Code: Select all

@WebServlet("/errorServlet")
public class MyServlet extends HttpServlet {
    public void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException{
         try{
             throw new NotEnoughFundException();
         }
         catch (NotEnoughFundException e){
             throw new ServletException (e);
         }
    }
}

Code: Select all

 <error-page>
         <exception-type>javax.servlet.ServletException</exception-type>
         <location>/errorPage.jsp</location>
 </error-page>

Re: About Question enthuware.jwpv6.2.739 :

Posted: Sat May 14, 2016 8:19 pm
by admin
Correct. It is possible to do so but is not a sensible way (as required by the question). You should not map ServletException. You should map the exception wrapped by the ServletException to an error page.