Error Handling
Python raises exceptions when things go wrong. Catch them with try/except.
try: 1 / 0except ZeroDivisionError as e: print("Cannot divide by zero")finally: print("Done")C# and JavaScript use try/catch blocks with similar semantics.
Practice Questions
Section titled “Practice Questions”- Which block runs regardless of success or failure?
Answer
`finally`. - What exception is thrown for invalid list access?
Answer
`IndexError`.