1 Chapter 11
Exceptions and Input/Output Operations
Date Chapter 11/6/2006 Chapter 10, start Chapter 11 11/13/2006 Chapter 11, start Chapter 12 11/20/2006 Chapter 12 11/27/2006 Chapter 13 12/4/2006 Final Exam 12/11/2006 Project Due
Topics
- Exception Handling
– Using try and catch Blocks – Catching Multiple Exceptions – User-Defined Exceptions
- The java.io Package
- Reading from the Java Console
- Reading and Writing Text Files
- Reading Structured Text Files Using StringTokenizer
- Reading and Writing Objects to a File
Exceptions
- Java is robust language and does not allow Illegal
- perations at run time to occur, they generate
exceptions, for example: – ArrayIndexOutOfBoundsException – ArithmeticException – NullPointerException – InputMismatchException – NumberFormatException
Handling Exceptions
- In a program without a Graphical User Interface,
exceptions cause the program to terminate.
- With this code:
12 String s = JOptionPane.showInputDialog( null, 13 "Enter an integer" ); … 17 int n = Integer.parseInt( s );
- If the user enters "a", we get this exception:
- See Example 11.1 DialogBoxInput.java