Solveeit Logo

Question

Computer Science Question on file handling

Arrange the following in correct order of exception handling in python:
Options:
(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:

A

(A), (B), (C), (D)

B

(A), (C), (B), (D)

C

(B), (A), (D), (C)

D

(C), (B), (D), (A)

Answer

(A), (C), (B), (D)

Explanation

Solution

Correct order for handling exceptions: write code in ‘try‘, handle specific exceptions in ‘except‘, raise exceptions with ‘raise‘ if needed, and execute final actions with ‘finally‘.