Recall & Review
beginner
What is the purpose of a
try block in Python?The
try block lets you test a block of code for errors. If an error occurs, Python stops running the try block and looks for an except block to handle the error.Click to reveal answer
beginner
What happens when an exception occurs inside a
try block?Python immediately stops executing the
try block and jumps to the matching except block to handle the error. If no matching except block is found, the program crashes.Click to reveal answer
beginner
Can code after the error inside a
try block run if an exception occurs?No. Once an exception happens, the rest of the
try block is skipped. The program moves to the except block.Click to reveal answer
intermediate
What is the role of the
else block in a try-except structure?The
else block runs only if no exceptions were raised in the try block. It is useful for code that should run only when everything in try succeeds.Click to reveal answer
intermediate
How does the
finally block behave in a try-except structure?The
finally block always runs after the try and except blocks, no matter what. It is used for cleanup actions like closing files or releasing resources.Click to reveal answer
What happens if no exception occurs in the
try block and there is an except block?✗ Incorrect
If no error happens, Python skips the
except block and continues normally.Where does Python jump when an exception occurs inside a
try block?✗ Incorrect
Python stops the
try block and jumps to the matching except block to handle the error.When does the
else block run in a try-except structure?✗ Incorrect
The
else block runs only if the try block finishes without errors.What is guaranteed about the
finally block?✗ Incorrect
The
finally block always runs after try and except, even if the program crashes.If an exception is not caught by any
except block, what happens?✗ Incorrect
If no
except block matches the error, the program stops and shows the error message.Explain the flow of execution in a try-except-else-finally structure when an exception occurs.
Think about which blocks run and which are skipped when an error happens.
You got /6 concepts.
Describe what happens when no exception occurs in a try-except-else-finally structure.
Focus on the normal flow without errors.
You got /4 concepts.