Notice: Due to an ongoing migration of our storage and publishing system, material requested since last month will not be uploaded for the time being, and new requests are paused. All existing notes remain available.

Unit 5 subjective questions Exception handling

ECAP776 20 questions with model answers. Write yours first, then compare.

Read the notes Practice MCQs
  1. Question 1 of 20

    Define an exception in Python. Explain how an exception differs from a syntax error.

  2. Question 2 of 20

    Explain the purpose and execution flow of Python's try and except statements with an example.

  3. Question 3 of 20

    Describe the roles of the else and finally clauses in exception handling. Illustrate their order of execution.

  4. Question 4 of 20

    Distinguish between catching multiple exceptions using separate except blocks and catching them using an exception tuple.

  5. Question 5 of 20

    Explain why the order of multiple except blocks is important when exceptions have an inheritance relationship.

  6. Question 6 of 20

    What is the significance of capturing an exception object with the as keyword? Demonstrate how useful information can be obtained from it.

  7. Question 7 of 20

    Compare a bare except clause, except Exception, and an exception-specific handler such as except ValueError.

  8. Question 8 of 20

    Explain exception propagation through nested function calls. What happens when no matching handler is found?

  9. Question 9 of 20

    Describe how the raise statement is used to generate exceptions explicitly. Write an example that validates a person's age.

  10. Question 10 of 20

    What does a bare raise statement do inside an except block? Explain re-raising with an example.

  11. Question 11 of 20

    Explain exception chaining using raise ... from .... Why is it useful when translating exceptions?

  12. Question 12 of 20

    Define a custom exception. Describe the steps for creating, raising, and catching one in Python.

  13. Question 13 of 20

    Design a custom exception hierarchy for a banking application and explain the advantages of using a common base exception.

  14. Question 14 of 20

    How can a custom exception store additional information? Create an exception for an invalid examination score and explain its attributes.

  15. Question 15 of 20

    Compare using built-in exception classes with defining custom exception classes. When should each approach be preferred?

  16. Question 16 of 20

    Analyze the following pattern and explain why placing too much code inside a try block can cause incorrect exception handling: try: value = int(text); save(value) except ValueError: print("Invalid input").

  17. Question 17 of 20

    Write and explain a Python function that repeatedly asks for two integers, handles invalid input and division by zero, and returns the quotient only after a successful calculation.

  18. Question 18 of 20

    Explain how exception handling should be applied when working with files. Include catching multiple exceptions and guaranteed cleanup.

  19. Question 19 of 20

    Discuss the relationship between return, exceptions, and the finally clause. Why is returning from finally considered dangerous?

  20. Question 20 of 20

    Develop a robust validation function for a percentage value. It must reject inappropriate types, values outside the valid range, and demonstrate a custom exception, exception chaining, and caller-side handling.

That's unit 5

Long answers stick best when they're tested again soon. Run the MCQs on this unit, then come back to the questions you found hardest.