Exception Handling Questions and Answers
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
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
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
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
15. Which exception is raised when converting an invalid string to integer?
- TypeError
- ConversionError
- ValueError
- InvalidError
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
17. Which exception is raised when importing a module that cannot be found?
- ModuleError
- ImportError
- NotFoundError
- LoadError
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
19. Which exception is raised when performing an operation on incompatible types?
- OperationError
- TypeError
- IncompatibleError
- ValueError
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