Catch the error, release the resource, always
A movie-ticket counter holds a seat the moment you start booking. Whether the booking succeeds or explodes, that seat has to be released — and that is exactly the shape finally was invented for.
This session has not been authored yet
You have reached a real page, but an empty one. The deck for Class 18 is planned in full in the course knowledge document and is queued for authoring — nothing on this page is finished teaching content.
The roster underneath is the actual plan for this session, so you can see exactly what will land here.
What this class will cover
- Class-18 openerThe hook: catch the error, release the resource, always.
- Basic try / catchThe syntax, and the exact path execution takes when something throws.
- finally — always runsThe cleanup block, and the handful of genuine exceptions to "always".
- Try-with-resourcesJava 7+,
AutoCloseable, and why it is cleaner than a hand-writtenfinally. - Multiple catch blocksOrder matters — specific before general, or the compiler stops you.
- PYQ · P1·Q3 · 2 marksMultiple catch blocks for a single try, with an example.
- Self-study · multi-catch in one blockJava 7's
catch (A | B e)— a convenience over two separate blocks. - throw vs throwsThe statement versus the declaration — the confusion the exam relies on.
- Worked example · movie-ticket bookingA counter catching
NumberFormatExceptionandArithmeticException, with the seat hold released infinallyon every path. - Activity 1 · debugging catch orderA general
catch(Exception e)sitting before a specific one — find why the compiler refuses it. - Activity 2 · fill in the finally blockWrite the two lines that release the seat and close the
Scanner, then the Class-18 close card.
Why a movie ticket, and not a payment
try / catch / finally only earns its keep when a resource must be released on both the success and the failure path. A held seat is exactly that shape — and it also seeds the MovieTicketCounter domain that Class 23 and Lab 5 will race threads against.