Vidyalelo
Python · all questions

Exception Handling in Python
practice.

Practice every MCQ with options. Use Show answers when you want the correct option and solution.

65

Questions

1/4

Page

Pick an option on a question to see the right answer and solution.

What is the purpose of exception handling in Python?

Select an option to see the answer and solution.

When is the finally block executed?

Select an option to see the answer and solution.

What is an exception in Python?

Select an option to see the answer and solution.

How many except statements can a try-except block have?

Select an option to see the answer and solution.

What will happen if an exception is raised in a try block and is not handled in any of the except blocks?

Select an option to see the answer and solution.

Which built-in Python function can be used to retrieve the error message associated with an exception?

Select an option to see the answer and solution.

When will the else part of try-except-else be executed?

Select an option to see the answer and solution.

Can one block of except statements handle multiple exception?

Select an option to see the answer and solution.

Which keyword is used to handle exceptions in Python?

Select an option to see the answer and solution.

Which of the following statements is true regarding the order of except clauses?

Select an option to see the answer and solution.

What is the purpose of the assert statement in Python?

Select an option to see the answer and solution.

The following Python code will result in an error if the input value is entered as -5.
assert False, 'Spanish'

Select an option to see the answer and solution.

What is the purpose of the except clause in a try block?

Select an option to see the answer and solution.

What is the output of the following code:
try:
x = 10 / 0
except ZeroDivisionError:
print("Error!")
finally:
print("Finally!")

Select an option to see the answer and solution.

Which of the following is not an exception handling keyword in Python?

Select an option to see the answer and solution.

What is the purpose of the else clause in a try block?

Select an option to see the answer and solution.

What is the purpose of the finally clause in a try block?

Select an option to see the answer and solution.

How can you create a custom exception class in Python?

Select an option to see the answer and solution.

What is the syntax to raise an exception manually in Python?

Select an option to see the answer and solution.

What will be the output of the following Python code?
def getMonth(m):
    if m<1 or m>12:
        raise ValueError("Invalid")
    print(m)
getMonth(6)

Select an option to see the answer and solution.