COMPSCI 61B Lecture Notes - Lecture 14: Call Stack, Stack Trace, Exception Handling
Document Summary
Can write to log or ash led to show error happened. Exceptions allow you to keep error-handling code separate from real code (consider pseudocode) There can be a lot of possible errors, so you can do try catch catch catch When exception is thrown, it descends the call stack until a method catches the exception. If an exception reaches the bottom of the stack, the program prints out a stack trace. Compiler requires that these be caught or speci ed. Goal: disallow compilation to prevent avoidable program crashes. Must be caught or declared to be thrown . If a checked exception has any possibility of occurring, they must be checked for or speci ed. Checked exceptions are unpredictable and may be hard to solve (ex. Enhanced for loop is really using the iterator. To use the enhanced for loop, the class needs to have an iterator iterator() and implements iterable.