Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations gkittelson on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Compile Error Help needed

Status
Not open for further replies.

MarkShark

Programmer
Aug 22, 2001
36
US
How do I fix the part of code for the following error code:

Exception java.io.IOException must be caught, or it must be declared in the throws clause of this method.

ObjectOutputStream out = new ObjectOutputStream(response.getOutputStream());

From the area of my servlet below:

private void handleException(HttpServletResponse response, Exception e)
{
e.printStackTrace();
ObjectOutputStream out = new ObjectOutputStream(response.getOutputStream());
out.writeObject(e.getMessage());
out.flush();
out.close();
}

 
Try:
Code:
  private void handleException(HttpServletResponse response, Exception e)
    {
         e.printStackTrace();
         ObjectOutputStream out;
         try {
           out = new ObjectOutputStream(response.getOutputStream());
           out.writeObject(e.getMessage());
           out.flush();
         }
         catch (IOException ioe) {
           /* Do whatever error handling */
         }
         finally {
           out.close();
         }
    }
Wushutwist
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top