Unit 2 home
Class 20 of 60 Part H · Slate UI24PC320CS
Placeholder · not written yet

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.

Class 20 Part H · C17–C20 13 pages planned 3 PYQs

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

  1. Class-20 openerThree exception questions, one class, all fully answerable by now.
  2. PYQ · P2·Q12b · 4 marksInvalidAgeException thrown for a negative age, with a re-prompt loop and full code.
  3. PYQ · P1·Q16b · 4 marksThe banking account array — index, negative-size, store and custom InsufficientFundsException, with multi-catch, throws and finally.
  4. PYQ · P1·Q12a · 4 marksThe insurance context — a four-class hierarchy with custom exceptions, full code and real terminal output.
  5. Exception chainingthrow new X("msg", cause) — when to wrap, and when to just rethrow.
  6. Best practicesNever swallow, log meaningfully, and never catch(Exception) on its own.
  7. Freshers get asked thisThree short interview-style exception questions, answered in a line or two each.
  8. Activity 1 · the swallowed exceptionAn empty catch block silently eats an error — explain exactly why that is dangerous.
  9. Activity 2 · quick quizFour true/false statements on exception practice, with a one-sentence reason for each.
  10. Activity 3 · reflectionWhich of the three PYQs felt hardest, and why.
  11. 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.