Exception Handling Questions and Answers
Practice ModeShowing 10 of 25 questions
Q1
What is the purpose of exception handling in Python?
Answer: Option B
Explanation: Exception handling allows programs to handle errors gracefully and continue execution.
Q2
Which keyword is used to handle exceptions in Python?
Answer: Option C
Explanation: The try-except block is used to catch and handle exceptions in Python.
Q3
What is the base class for all exceptions in Python?
Answer: Option B
Explanation: BaseException is the base class for all built-in exceptions in Python.
Q4
Which exception is raised when a variable is not found?
Answer: Option C
Explanation: NameError is raised when a local or global name is not found.
Q5
What does the "finally" block do in exception handling?
Answer: Option C
Explanation: The finally block always executes, regardless of whether an exception occurred or not.
Q6
Which exception is raised when dividing by zero?
Answer: Option C
Explanation: ZeroDivisionError is raised when the second argument of division or modulo operation is zero.
Q7
What is the purpose of the "else" clause in try-except blocks?
Answer: Option B
Explanation: The else clause executes only if no exception was raised in the try block.
Q8
How can you raise an exception manually in Python?
Answer: Option B
Explanation: The raise statement is used to manually trigger exceptions in Python.
Q9
Which exception is raised when accessing a non-existent list index?
Answer: Option B
Explanation: IndexError is raised when a sequence subscript is out of range.
Q10
What does the "except Exception as e" syntax do?
Answer: Option B
Explanation: This syntax catches all exceptions derived from Exception class and assigns the exception object to variable e.