CSC 102 Lecture Notes Week 5
Shallowness and Deepness
Exceptions
File I/O
Figure 1: State of memory after line 23 of CircleTester.java.
try {}code that may throw
...
code to handle exception }
...
Throwable Error IOError VirtualMachineError ... Exception IOException RuntimeException IndexOutOfBoundsException NullPointerException ... ...
"serious problems that a reasonable application should not try to catch"
"a form of Throwable that indicates conditions that a reasonable application might want to catch"
"exceptions that can be thrown during the normal operation of the Java Virtual Machine"
if (amount > balance) { throw new InsufficientFundsException(...); }
public class InsufficientFundsExcpetion extends IllegalArgumentException { public InsufficientFundsException( String message) { super(message); } }
Scanner s = new Scanner(new File(filename))where filename is a String.
where filename is a StringPrintStream ps = new PrintStream(filename)