Chapter 11: Input/Output and Exception Handling

Catching Exceptions

try
{
  // code that might generate an IOException or a FileNotFoundException
}
catch (IOException exception)
{
  // handle the exception
}
catch (FileNotFoundException exception)
{
  // handle the exception
}
finally 
{
  // this code gets executed regardless of what else occurred
  // e.g. out.close();
}

Custom Exceptions

public class WhateverException extends RunTimeException
{
  public WhateverException()
  {
  }

  public WhateverException(String message)
  {
    super(message);
  }
}

Lecture Code

Valid XHTML 1.0!