COMPSCI 61B Lecture Notes - Lecture 14: Stack Trace, Call Stack, Pseudocode
Document Summary
When something goes wrong, break the ow of control. We can also throw our own exceptions using the throw keyword. Can provide more informative message to a user. Can provide more information to some sort of error handling code. Used to handle errors, e. g. you try to use 383,124 gigabytes of memory. You try to cast an object as a dog, but dynamic type is not dog. You try to call a method using a reference variable that is equal to null. You try to access index -1 in an array. Exceptions are instances of classes like most everything else in java. Can catch" exceptions instead, preventing program from crashing. Use the keywords try and catch to break normal ow. Allows you to keep error handling code separate from real" code. When an exception is thrown, it descends the call stack.