Computer Science
Assertion (A): No matter what exception occurs, you can always make sure that some common action takes place for all types of exceptions.
Reasoning (R): The finally block contains the code that must execute.
- Both A and R are true and R is the correct explanation of A.
- Both A and R are true but R is not the correct explanation of A.
- A is true but R is false.
- A is false but R is true.
Python Exception Handling
1 Like
Answer
Both A and R are true and R is the correct explanation of A.
Explanation
The 'finally' block contains code that must execute, irrespective of whether an exception is raised. This ensures that some common action takes place for all types of exceptions, no matter which exception occurs.
Answered By
1 Like
Related Questions
Assertion (A): Exception handling code is separate from normal code.
Reasoning (R): Program logic is different while exception handling code uses specific keywords to handle exceptions.
- Both A and R are true and R is the correct explanation of A.
- Both A and R are true but R is not the correct explanation of A.
- A is true but R is false.
- A is false but R is true.
Assertion (A): Exception handling code is clear and block based in Python.
Reasoning (R): The code where unexpected runtime exception may occur is separate from the code where the action takes place when an exception occurs.
- Both A and R are true and R is the correct explanation of A.
- Both A and R are true but R is not the correct explanation of A.
- A is true but R is false.
- A is false but R is true.
What all can be the possible outputs of the following code?
def myfunc (x=None) : result = "" if x is None: result = "No argument given" elif x == 0: result = "Zero" elif 0 < x <= 3: result = "x is between 0 and 3" else: result = "x is more than 3" return result c = myfunc (3.5) print (c)
List the situation(s) in which the following errors occur:
(a) IOError
(b) NameError
(c) ValueError
(d) TypeError