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

What might go wrong inside the outer try{} block which would cause an exception?

Answer:

(1) One of the files might not open. (2) There might be an error in reading from a file. (3) There might be an error in writing to a file. (4) One of the files might not close.


FileNotFoundException

    . . . . 
try
{
  instr = 
  outstr = 
  try
  {
  }
  catch ( EOFException  eof )
  {
  }

}

catch(  )
{
}

catch(   )
{
}

All of those problems are IOExceptions so the outer try{} could catch them all with one catch{} block. But this one block would not be very specific about which type of error it caught.

The constructors for FileInputStream and FileOutputStream throw a FileNotFoundException when there is a problem. Its catch{} block should precede the one for IOException.


QUESTION 20:

Fill in the blanks. (Copy and Paste from the first paragraph.)


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