Programming with Python - Exceptions

0.0(0)
Studied by 0 people
call kaiCall Kai
Locked
learnLearn
examPractice Test
spaced repetitionSpaced Repetition
heart puzzleMatch
flashcardsFlashcards
GameKnowt Play
Card Sorting

1/25

flashcard set

Earn XP

Description and Tags

Chapter 10 - Exceptions

Last updated 4:06 PM on 8/17/26
Name
Mastery
Learn
Test
Matching
Spaced
Call with Kai
Chat

No analytics yet

Send a link to your students to track their progress

26 Terms

1
New cards
Why programs need exception-handling code
To prevent crashes when input, files, or operations fail.
2
New cards
What an exception is in Python
A runtime error that stops normal execution unless handled.
3
New cards
Purpose of handling exceptions
To catch errors, show messages, and keep the program running.
4
New cards
How a try/except block works

Try runs normally if error occurs, jump to except.

5
New cards
What happens when no exception occurs in a try block
Try runs fully and except is skipped.
6
New cards
Why try/except is better than manual checking
It handles unexpected issues cleanly without messy code.
7
New cards
Why programs use multiple except blocks
To handle different error types appropriately.
8
New cards
How Python chooses which except block to run
It runs the first matching except only.
9
New cards
Why bare except should be avoided
It hides bugs by catching every error.
10
New cards
What happens if an exception is not handled
The program stops and prints a traceback.
11
New cards
How to handle multiple exception types in one except
Use a tuple: except (ValueError, TypeError).
12
New cards
What the raise statement does
Stops normal flow and triggers an exception immediately.
13
New cards
Why raising exceptions keeps code cleaner
It separates normal logic from error-handling.
14
New cards
Why ValueError is used for invalid numeric input
It signals the value itself is unacceptable.
15
New cards
What printing an exception object shows
The custom message passed to raise.
16
New cards
How exceptions travel up the call stack
They exit the function and move to the caller’s except.
17
New cards
Why exception propagation improves structure
Keeps functions simple while callers handle errors.
18
New cards
Why returning special values is inferior
Sentinel values require extra checks and hide errors.
19
New cards
Purpose of the finally block
Code that must run no matter what happens.
20
New cards
Execution rules for finally
Runs after success, handled error, unhandled error, or early exit.
21
New cards
Why finally is essential for file handling
Ensures files close even if errors occur.
22
New cards
Why custom exceptions are useful
They represent specific, meaningful program errors.
23
New cards
How to define a custom exception type
Create a class inheriting from Exception.
24
New cards
Why custom exception names end with “Error”
Follows Python naming conventions.
25
New cards
How to raise a custom exception
Use raise CustomError("message").
26
New cards
How to handle a custom exception
Catch it with except CustomError as e: