Question:medium

Arrange the following in correct order of exception handling in python:
(A) Write the code that may raise an exception inside a try block
(B) Execute some code regardless of whether the exception occurs or not using the finally block
(C) Handle the specific exception using the except block
(D) Raise the exception using the raise statement if necessary
Choose the correct answer from the options given below:

Updated On: Jan 16, 2026
  • (A), (B), (C), (D)
  • (A), (C), (B), (D)
  • (B), (A), (D), (C)
  • (C), (B), (D), (A)
Show Solution

The Correct Option is B

Solution and Explanation

Python's exception handling adheres to a defined sequence for effective error management. The correct order is as follows:

  1. (A) Enclose potentially problematic code within a try block: This segment is designated for code that might trigger exceptions.
  2. (C) Address specific exceptions with an except block: This block is designed to intercept and manage exceptions originating from the try block.
  3. (B) Implement cleanup code using a finally block: The finally block, which is optional, executes irrespective of whether an exception occurred. It's used for essential cleanup tasks like closing files or freeing resources.
  4. (D) Manually trigger exceptions with the raise statement: In specific scenarios, explicit exception raising might be necessary, often within an except block or contingent on particular conditions.

Consequently, the correct procedural sequence is: (A), (C), (B), (D).

Was this answer helpful?
0


Questions Asked in CUET (UG) exam