go to previous page   go to home page   go to next page

Answer:

Yes.


Nested try{} Blocks

try
{
  // other stuff goes here


  try
  {
    while ( true )
      sum += instr.readInt();
  }
  catch ( EOFException eof )
  {
    System.out.println( "The sum is: " + sum );
    instr.close(); 
  }
  catch ( IOException iox )
  {
    System.out.println( "Problems reading " + fileName );
    instr.close(); 
  }

}

catch ( IOException iox )
{
  System.out.println( "I/O Problems with" + fileName );
}

A method can catch some exceptions and not others. Since problems with closing a file are rare, and there is not much you can do when it happens, not catching this exception would be tolerable. The logic is messy. I/O programming often is.

This example is probably more complicated than you would normally write. But a commercial-grade program should take care of everything.


QUESTION 12:

If the readInt() throws an IOException, where will it be caught?


go to previous page   go to home page   go to next page