W3Tutorials.net
Toggle Menu
Home
Online Go Compiler
Tutorials
Javascript Tutorials
Python Tutorials
Go Tutorials
Blog
All Posts
Python Error Handling
Check your understanding of try/except,exceptions,and error best practices.
1. Which block in Python error handling executes code regardless of whether an exception occurred or not?
try
except
finally
else
2. Which of the following are built-in exceptions in Python? (Select all that apply)
ValueError
FileNotFoundError
CustomError
TypeError
3. A 'try' block in Python can exist without an 'except' or 'finally' block.
True
False
4. What keyword is used to manually trigger an exception in Python?
5. Which exception is raised when you try to access a non-existent key in a dictionary?
IndexError
KeyError
ValueError
TypeError
6. Which clauses can follow a 'try' block in Python? (Select all that apply)
except
else
finally
catch
7. The 'else' clause in a try-except block executes only if no exceptions were raised in the 'try' block.
True
False
8. What is the name of the block that contains code to handle specific exceptions (abbrev. or full name)?
9. Which exception is raised when you try to call a method on an object that does not support it (e.g., '5.append(3)')?
AttributeError
TypeError
ValueError
MethodError
10. Which of the following are valid use cases for custom exceptions? (Select all that apply)
To handle application-specific error conditions
To make error messages more descriptive
To automatically fix errors without user intervention
To group related errors under a common exception type
Reset
Answered 0 of 0 — 0 correct