READING CHAPTER 8 SECTION 1 "Catching Exceptions" - reliable program - correct results for all valid input - robustness - doesn't crash easily even when input invalid - *exception handling* - *assertion* - mechanism to help catch logical errors during development - supervisor-subordinate design pattern - exception-handling mechanism - type of control structure - *exception* - error condition that can occur during the normal course of program execution - when occurs - "exception is thrown" - normal sequence of flow is terminated - exception-handling routine is executed - "exception is caught" - have already seen exceptions - so far have left system to handle exceptions - single error often results in wrong behavior or termination - increase robustness by having programmer catch - *try-catch* control statement - syntax: try { // block including a statement that could throw an exception } catch ( // declaration of name and type of exception to catch ) { // exception-handling block } - if an exception occurs, any statements in the try block after the statement that causes the exception are not executed - if no exception is thrown, the catch block is not executed - catch block can only catch one type of exception - exceptions are instances of the Throwable class or its subclasses - Throwable subclasses - Exception - represent error conditions that should be caught by ordinary programs - Error - represent error conditions that are too serious to be handled by ordinary programs - Throwable methods - get information about the thrown exception - called inside the catch block - instance - no arguments - getMessage - printStackTrace - what would have been printed before the program crashes if we hadn't caught the exception - sequence of calls made from the main method of the main class to the method that throws the exception Quick Check 1. Okay 1 Error 2. The while statement is inside the try statement, so as soon as there is an error, the body of the try statement stops executing and control goes to the catch statement. Control is never returned to the try statement, so the loop will not continue.