python Exceptions Questions & Answers

Question 1: Which of the following is not the built-in error type?

Question 2: What type of error will be raised when the imported module is not found?

Question 3: What will be the output of the following code?

def fn(x):
	try:
		print(5/x)
	except:
		print('Error occurred')
fn(0)
ADVERTISEMENT

Question 4: What will be the output of the following code?

def fn(x):
	try:
		print(5/x)
	except ZeroDivisionError:
		print("except block")
	else:
		print("else block")
	finally:
		print("finally block")
fn(0)

Question 5: Which of the following keyword is used to raise an error in Python?