Chapter 3 · Class 12 · CBSE · Science Computer Science
Exception Handling in Python
25 practice questions · 5 marks weightage
Topics in this chapter
- Try-Except Blocks and Built-in Exceptions
- Else and Finally Blocks in Exception Handling
- Raising Exceptions and User-Defined Custom Exceptions
- Exception Propagation and Control Flow
- Advanced Exception Handling and Best Practices
Cheat sheet
Cheat SheetPractice questions
- Question 1Q-4D2F62See the answer and solution
What is the main purpose of the finally block in Python exception handling?
- A.It executes only when an exception occurs.
- B.It executes only when no exception occurs.
- C.It executes whether or not an exception occurs.
- D.It is used only to define custom exceptions.
- Question 2Q-F79368See the answer and solution
What will be the output of the following Python code? try: value = int("10") except ValueError: print("invalid") else: print(value / 4) finally: print("finished")
- A.invalid finished
- B.2.5 finished
- C.2 finished
- D.finished
- Question 3Q-291D67See the answer and solution
Explain why specific exception classes should generally be handled before a general exception class such as Exception. Include a short Python example showing the correct order.
- Question 4Q-E4AC3CSee the answer and solution
What is printed by the following Python code? try: number = int("abc") except ValueError: print("A") except TypeError: print("B")
- A.A
- B.B
- C.abc
- D.The program terminates without output
- Question 5Q-6E2DC5See the answer and solution
What is printed by the following Python code? try: try: int("x") except ValueError: raise RuntimeError("bad input") except RuntimeError as error: print(type(error).name)
- A.ValueError
- B.RuntimeError
- C.bad input
- D.No output because the inner exception is ignored
20 more questions on Exception Handling in Python
Sign up free to practise the full chapter. Questions you get wrong come back until you've mastered them.
Start practising freeFree to start · No credit card needed