Skip to content

Language

Sign in

Learn › Class 12 › Computer Science / Informatics Practices › Python revision, functions, exceptions

Exception handling

Remember

  • Syntax errors stop a program before it runs; exceptions happen while it runs.
  • try → except (on error) → else (no error) → finally (always).
  • Use raise to signal an error and assert to check a condition.

Quick self-check

  1. Why put specific except blocks before a general except?

    Check

    Python uses the first matching block, so a general one first would hide the specific ones.

  2. Which exception does d['x'] raise if the key is missing?

    Check

    KeyError.

Reviewed by EduFlint team on 1 Dec 2026 · version 1

Written by us for this site. Independent; not affiliated with NCERT or CBSE.

Report a mistake

Looking for another topic?