Exception Handling Flashcards
6 cards from real PCAP practice questions. Tap to flip, then mark Knew It or Still Learning — missed cards come back until you master them.
Read the first 6 Exception Handling flashcards as text
What is the purpose of the `assert` statement in Python?
Answer: To test a condition and raise AssertionError if false
`assert` tests a condition and raises `AssertionError` if the condition evaluates to False.
Which exception is raised when you try to open a file that does not exist?
Answer: FileNotFoundError
`FileNotFoundError` is a subclass of `OSError` raised when a file or directory is not found.
What happens if an exception is raised inside a `finally` block?
Answer: It replaces any previously raised exception
An exception raised in a `finally` block replaces and discards any exception currently being propagated.
Which exception type is raised when a function receives an argument of the wrong type?
Answer: TypeError
`TypeError` is raised when an operation or function is applied to an object of an inappropriate type.
What does `raise` without an argument do inside an `except` block?
Answer: Re-raises the currently handled exception
A bare `raise` statement re-raises the most recently caught exception with its original traceback.
Which exception is raised when a function receives an argument with an incorrect value?
Answer: ValueError
`ValueError` is raised when an operation receives an argument of the right type but an inappropriate value.
How this page was made: written with AI tools and published by Nathan Beja, founder of Practice Test Geeks, who is responsible for its content. Exam facts are checked against the official sources listed below. Not reviewed by a subject-matter expert. Editorial policy
Sources & references
Exam facts on this page (fees, format, dates, passing scores) are checked against these official sources; the date is our last check. Editorial policy
- pythoninstitute.org — Eligibility, fees, exam format, passing score, retake fee, retake policy, score release, time limit, score validity, exam information · verified Oct 2026
- home.pearsonvue.com — Test delivery · verified Oct 2026