Last reviewed
Correct answer: D. It lets a program handle an error gracefully instead of crashing outright
Explanation
A try/except block does not make errors disappear; it decides who deals with one when it arrives. The reference puts it plainly: "The try statement specifies exception handlers and/or cleanup code for a group of statements." When something raises inside the guarded code, "If an exception occurs during execution of the try clause, the rest of the clause is skipped" and control jumps to a matching except, so your program keeps running instead of stopping with a traceback.
What matters tomorrow is how narrowly you catch. Catching ValueError around a call to int() handles bad input and nothing else; wrapping the same lines in a bare except also swallows the misspelled variable name three lines down, and you lose an hour to a function that silently returns nothing. The tutorial's guidance is "to be as specific as possible with the types of exceptions that we intend to handle, and to allow any unexpected exceptions to propagate on." Put the code that should run only when nothing raised in an else clause, and cleanup that must happen either way in finally.
Sources
“The try statement specifies exception handlers and/or cleanup code for a group of statements”
“it is good practice to be as specific as possible with the types of exceptions that we intend to handle, and to allow any unexpected exceptions to propagate on.”
“If a finally clause is present, the finally clause will execute as the last task before the try statement completes.”
Practise 3 questions on this topic
Take Python Basics — Timed Test (3 questions) — scored instantly, explanation for every question, no login.