Python Programming - Exception Handling

Exercise : Exception Handling - General Questions
  • Exception Handling - General Questions
36.
Which of the following is a built-in exception in Python for handling errors related to importing modules that do not exist?
ImportError
ModuleNotFoundError
NoSuchModuleError
ModuleImportError
Answer: Option
Explanation:
ModuleNotFoundError is raised when attempting to import a module that does not exist.

37.
What is the purpose of the with statement in Python for file handling?
It raises exceptions
It terminates the program
It ensures proper resource cleanup
It defines custom exception classes
Answer: Option
Explanation:
The with statement is used for file handling in Python and ensures proper resource cleanup by automatically closing the file when the block is exited, even if an exception occurs.