What to do with exceptions in java? -


i beginner in java programming. have code below

  socket socket = serversocketobj.accept();   bufferedwriter writer = new bufferedwriter(new outputstreamwriter(socket.getoutputstream()));   try {     writer.writeline();   } catch(ioexception e ) {     //write logger here   } {     writer.close(); // throws ioexceptioin too.     // possible memmory leak?     socket.close();   } 

when try close writer should handle exception. don't know it. exception impossible in case? can ignore it?

if don't know them, catch them , log them.
simplest way of logging them e.printstacktrace() way,
@ least you'll see there's problem if exception occurs.

another approach re-throw exceptions upper-level code.
e.g. if method (in sample code is) declares throw ioexception,
there's nothing should worry about. let upper-level code worry it.


Comments

Popular posts from this blog

html - Sizing a high-res image (~8MB) to display entirely in a small div (circular, diameter 100px) -

java - IntelliJ - No such instance method -

identifier - Is it possible for an html5 document to have two ids? -