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
1. What is the purpose of exception handling in Python?
- To terminate the program immediately when an error occurs
- To handle errors gracefully and continue program execution
- To ignore all errors in the program
- To make the program run faster
2. Which keyword is used to handle exceptions in Python?
- catch
- throw
- try-except
- handle
3. What is the base class for all exceptions in Python?
- Exception
- BaseException
- Error
- BaseError
4. Which exception is raised when a variable is not found?
- VariableError
- NotFoundError
- NameError
- UndefinedError
5. What does the "finally" block do in exception handling?
- Executes only when no exception occurs
- Executes only when an exception occurs
- Always executes regardless of exceptions
- Never executes
6. Which exception is raised when dividing by zero?
- DivisionError
- MathError
- ZeroDivisionError
- ArithmeticError
7. What is the purpose of the "else" clause in try-except blocks?
- Executes when an exception occurs
- Executes only if no exception occurs in try block
- Always executes
- Executes before the try block
8. How can you raise an exception manually in Python?
- throw
- raise
- exception
- trigger
9. Which exception is raised when accessing a non-existent list index?
- KeyError
- IndexError
- ListError
- RangeError
10. What does the "except Exception as e" syntax do?
- Catches all exceptions and stores in e
- Catches only Exception class and stores in e
- Ignores all exceptions
- Raises a new exception