Three exam questions on exceptions, all answerable in one class
Everything Classes 17 to 19 built now gets spent on real past papers — the age validator, the banking multi-catch, and the insurance hierarchy — then chaining, best practices, and the cheat sheet that carries you into Lab 4.
This session has not been authored yet
You have reached a real page, but an empty one. The deck for Class 20 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-20 openerThree exception questions, one class, all fully answerable by now.
- PYQ · P2·Q12b · 4 marks
InvalidAgeExceptionthrown for a negative age, with a re-prompt loop and full code. - PYQ · P1·Q16b · 4 marksThe banking account array — index, negative-size, store and custom
InsufficientFundsException, with multi-catch,throwsandfinally. - PYQ · P1·Q12a · 4 marksThe insurance context — a four-class hierarchy with custom exceptions, full code and real terminal output.
- Exception chaining
throw new X("msg", cause)— when to wrap, and when to just rethrow. - Best practicesNever swallow, log meaningfully, and never
catch(Exception)on its own. - Freshers get asked thisThree short interview-style exception questions, answered in a line or two each.
- Activity 1 · the swallowed exceptionAn empty
catchblock silently eats an error — explain exactly why that is dangerous. - Activity 2 · quick quizFour true/false statements on exception practice, with a one-sentence reason for each.
- Activity 3 · reflectionWhich of the three PYQs felt hardest, and why.
- Mid-unit consolidation + cheat sheetClasses 17–20 tied together, one line each for hierarchy, checked/unchecked, try/catch/finally, throw/throws and custom exceptions — then the Lab 4 runway.
Where UPI finally fits
The banking PYQ is the one place UPI genuinely belongs — an atomic debit-and-credit that either fully happens or throws is exactly what InsufficientFundsException is motivated by. That framing returns here, and again in Lab 4.