Chapter-1 Exception Handling in Python — Online MCQ Test
COMPUTER SCIENCE · Grade 12 · CBSE(NCERT)
Practice Chapter-1 Exception Handling in Python with a free chapter-wise online MCQ test.
This chapter covers: try - except - else - finally - runtime errors - exception handling.
AI-generated questions from basic to board-exam level, with instant results and explanations.
Chapter-1 Exception Handling in Python — Important Questions & Answers
What is an exception in Python?
- A. A type of loop used in programming
- B. An event that occurs during program execution that disrupts the normal flow of the program
- C. A function that always returns an error
- D. A variable that stores error messages
Answer: B. An event that occurs during program execution that disrupts the normal flow of the program
An exception is an error event that disrupts normal program execution, which Python handles using exception handling mechanisms.
An exception is an error event that disrupts normal program execution, which Python handles using exception handling mechanisms.
Which keyword is used to catch an exception in Python?
- A. catch
- B. handle
- C. except
- D. error
Answer: C. except
The 'except' keyword is used in Python to catch and handle exceptions that occur in the try block.
The 'except' keyword is used in Python to catch and handle exceptions that occur in the try block.
What happens if an exception is not caught in a try-except block?
- A. The program continues normally
- B. The program terminates and displays an error message
- C. The program ignores the error
- D. The program automatically fixes the error
Answer: B. The program terminates and displays an error message
If an uncaught exception occurs, the program terminates and Python displays a traceback showing the error details.
If an uncaught exception occurs, the program terminates and Python displays a traceback showing the error details.
Which exception would be caught by 'except (ValueError, TypeError):'?
- A. Only ValueError
- B. Only TypeError
- C. Either ValueError or TypeError
- D. None of the above
Answer: C. Either ValueError or TypeError
Using a tuple of exception types allows catching multiple specific exceptions in a single except block.
Using a tuple of exception types allows catching multiple specific exceptions in a single except block.
What is the output of this code? try: raise ValueError('Invalid value') except ValueError as e: print(f'Caught: {e}') finally: print('Cleanup')
- A. Caught: Invalid value\nCleanup
- B. Cleanup
- C. Caught: Invalid value
- D. Invalid value
Answer: A. Caught: Invalid value\nCleanup
The ValueError is raised and caught, printing 'Caught: Invalid value', then finally block executes printing 'Cleanup' on a new line.
The ValueError is raised and caught, printing 'Caught: Invalid value', then finally block executes printing 'Cleanup' on a new line.