Exception Handling Questions and Answers
Practice ModeShowing 10 of 25 questions
Q21
Which method is called when using the "with" statement for resource management?
Answer: Option C
Explanation: The with statement calls the __enter__ method at start and __exit__ method at end for context management.
Q22
What exception is raised when a file cannot be found?
Answer: Option C
Explanation: FileNotFoundError is raised when a file or directory is requested but doesn't exist.
Q23
How can you catch multiple exceptions in a single except block?
Answer: Option B
Explanation: Multiple exceptions can be caught by specifying them as a tuple in the except clause.
Q24
What is the purpose of the traceback module?
Answer: Option C
Explanation: The traceback module provides utilities for extracting, formatting, and printing stack traces.
Q25
Which exception is raised when there is an indentation error?
Answer: Option B
Explanation: IndentationError is raised when there is incorrect indentation in the code.