Questions: Error Handling and Exceptions

5 questions to test your understanding

Score: 0 / 5
Question 1 Multiple Choice

A Python program uses a bare `except: pass` to wrap its main processing function. It works fine in testing. In production, users report they cannot stop the program with Ctrl+C. What is the most likely cause?

AThe `pass` statement should be replaced with a `return` statement to allow clean exits
BA bare `except:` catches all exceptions including `KeyboardInterrupt`, silently swallowing the signal that would otherwise stop the program
CThe `try` block needs to be wrapped in a `while` loop to handle repeated exceptions in production
DThe function raises too many different exception types for a single handler to manage
Question 2 Multiple Choice

A function opens a network connection, performs an operation that might fail, and must close the connection whether the operation succeeds or fails. Which structure handles this correctly?

APut the close call inside both the try and except blocks separately
BUse a `finally` block, which runs regardless of whether an exception was raised
CUse an `else` block, which runs only if no exception occurred
DWrap the entire function in an outer try-except and close the connection in the outer handler
Question 3 True / False

Catching a specific exception type (e.g., `except ValueError`) is better practice than using a bare `except:` clause.

TTrue
FFalse
Question 4 True / False

Using try-except blocks is the best way to prevent invalid user input from reaching your program, replacing the need for upfront input validation.

TTrue
FFalse
Question 5 Short Answer

What is the difference between error prevention and error handling, and when is each approach appropriate?

Think about your answer, then reveal below.