CS 121 Lecture 69: The try-catch Statement
Document Summary
The try-catch statement: identifies a block of statements that may throw an exception. A product code includes, among other info, a character in the. 10th position that represents the zone from which that product was made. & a 4-digit integer in positions 4 through 7 that represents the district in which it will be sold. Due to some recognition, products from zone r are banned from being sold in districts w/ a designation of 2000 or higher. A try statement contains a block of code followed by 1 or more catch clauses. If an exception occurs in the try block, the code of the corresponding catch cause is executed. The finally clause, if present, is executed no matter how the try block is exited. The finally clause: defines a section of code that is executed no matter how the try block is exited. A try-catch statement can have an optional finally clause.