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

php - regexp cyrillic filename not matches -

c# - OpenXML hanging while writing elements -

sql - Select Query has unexpected multiple records (MS Access) -