Exception Handling Questions and Answers

Take Exam

Python Programming - Exception Handling Questions with Answers teach how to manage runtime errors safely. These Python Exception Handling Questions are vital for Infosys, TCS, and RRB exams to test coding accuracy and fault tolerance

Exception Handling

Showing 10 of 25 questions

11. Which exception is raised when a dictionary key is not found?

  • KeyError
  • DictError
  • NotFoundError
  • IndexError
Show Answer Report

12. What is the difference between SyntaxError and Exception?

  • SyntaxError occurs at runtime, Exception at compile time
  • SyntaxError occurs during parsing, Exception during execution
  • Both are the same
  • Exception occurs during parsing, SyntaxError during execution
Show Answer Report

13. How can you create a custom exception in Python?

  • Using the "custom" keyword
  • By creating a class that inherits from Exception
  • Using the "new_exception" function
  • Custom exceptions are not possible in Python
Show Answer Report

14. What happens if an exception is not caught in Python?

  • The program continues silently
  • The exception is logged and ignored
  • The program terminates with a traceback
  • The exception is automatically fixed
Show Answer Report

15. Which exception is raised when converting an invalid string to integer?

  • TypeError
  • ConversionError
  • ValueError
  • InvalidError
Show Answer Report

16. What is the purpose of multiple except blocks?

  • To handle the same exception multiple times
  • To handle different exception types specifically
  • To make code run faster
  • To ignore multiple exceptions
Show Answer Report

17. Which exception is raised when importing a module that cannot be found?

  • ModuleError
  • ImportError
  • NotFoundError
  • LoadError
Show Answer Report

18. What does the "assert" statement do in Python?

  • Always raises an exception
  • Tests a condition and raises AssertionError if False
  • Ignores all exceptions
  • Creates a new variable
Show Answer Report

19. Which exception is raised when performing an operation on incompatible types?

  • OperationError
  • TypeError
  • IncompatibleError
  • ValueError
Show Answer Report

20. What is the difference between except: and except Exception:

  • There is no difference
  • except: catches all, except Exception: catches only regular exceptions
  • except Exception: catches more exceptions
  • except: is faster
Show Answer Report
Questions and Answers for Competitive Exams Various Entrance Test