Sunday 15 March 2015

xml - How can I make my Java Servlet class handle SAXException's? -


When I compile my Java sublett code, I get the following error ...

  javax.servlet.http.HttpServlet; Overridden method does not throw org.xml.sax.SAXException  

In my overridden doGet () function, I am using JAXP to process XML, which apparently I need to handle SAXExceptions. But when I tax "SAXExeption" in the list of exception types, I want to work to handle my doGet, I get the above error.

You can not declare an overriding method, which throws the checked exceptions, which does not throw the method override has gone. In other words, HttpServlet.doGet () has been declared as throwing IOException and ServletException, so you can not use any exception type in your doGet method's Forage Clause.

However, you can wrap SAXException as a servicelet to get around it:

  Secure zero code (HTTPPrilateral request) HTPserve Response Response Servicelet Specification {JxP.PolicyHARASXExation ()); } Grip (SAXException E) {New Service Exception ("Parsing Failure near JNSP", e); }}  

No comments:

Post a Comment