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 Sheet

Practice questions

  1. Question 1Q-4D2F62

    What is the main purpose of the finally block in Python exception handling?

    1. A.It executes only when an exception occurs.
    2. B.It executes only when no exception occurs.
    3. C.It executes whether or not an exception occurs.
    4. D.It is used only to define custom exceptions.
    See the answer and solution
  2. Question 2Q-F79368

    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")

    1. A.invalid finished
    2. B.2.5 finished
    3. C.2 finished
    4. D.finished
    See the answer and solution
  3. Question 3Q-291D67

    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.

    See the answer and solution
  4. Question 4Q-E4AC3C

    What is printed by the following Python code? try: number = int("abc") except ValueError: print("A") except TypeError: print("B")

    1. A.A
    2. B.B
    3. C.abc
    4. D.The program terminates without output
    See the answer and solution
  5. Question 5Q-6E2DC5

    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)

    1. A.ValueError
    2. B.RuntimeError
    3. C.bad input
    4. D.No output because the inner exception is ignored
    See the answer and solution

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 free

Free to start · No credit card needed