Does DataInputStream.close() throw an exception?

A good answer might be:

Yes, it throws an IOException

Exception thrown by a catch{} Block

So there is a problem. The close() method inside the catch{} block throws an IOException which is not caught.

// Loop with problems

  while ( true )
    sum += instr.readInt();

catch ( EOFException eof )
  System.out.println( "The sum is: " + sum );
  instr.close(); <—— throws IOException 

catch ( IOException eof ) <—— this  catch is for the try{} block 
{                              not for the previous catch{} block
  System.out.println( "Problem reading input" );
  instr.close(); <—— throws IOException 

There are various ways to deal with this. One possibility is not to catch the exception that close() throws. Then the method header must be

public static void main(String[] args) throws IOException


Can a try{}/catch{} be nested inside an outer try{} block?