WorksheetsException Handling
Total questions: 25
Worksheet time: 12mins
The unexpected event happened during program execution should be handled by
EXCEPTION
EXPERIMENT
ASSERTION
EXTRAORDINARY
try:
a=int(input("\n Enter a Value"))
b=int(input("\n Enter a Value "))
c=a/b
print (c)
except:
print("\n Something Went Wrong")
Assume a = 10 and b = 5, then the output will be
5.0
Something Went Wrong
Arithmetic Error
2.0
Exception disrupts the
Normal flow of the program
Abnornal flow of the program
Hard Disk
None of the Above
The suspicious code is put inside the
Try Block
Finally Block
Else Block
Except Block
________ statement can also be used without specifying Exception.
Try
Finally
Except
Else
try:
a=10/5
print (a)
except ArithmeticError:
print ("This statement is raising an exception" )
finally:
print (" final block executed " )
2.0
final block executed
This statement is raising an exception
final block executed
final block executed
2.0
An exception can be manually triggered by the command
raise
try
except
trigger
n= int(input("Please enter an integer: "))
if n < 0:
raise Exception (" Only Positive Numbers are Allowed ")
print ("Great, you successfully entered an integer!")
what is the output if the given input is -12
Great, you successfully entered an integer!
Only Positive Numbers are Allowed
Only Positive Numbers are Allowed
Great, you successfully entered an integer!
None of the above Option
User defined Exceptions are created from the _________ Parent Class
Exception
Except
Handler
User Defined Exception
How many except statements can a try-except block have?
zero
one
more than one
more than zero
When will the else part of try-except-else be executed?
a) always
b) when an exception occurs
c) when no exception occurs
d) when an exception occurs in to except block
Is the following Python code valid?
try:
# Do something
except:
# Do something
else:
# Do something
no, there is no such thing as else
no, else cannot be used with except
no, else must come before except
yes
What will be the output of the following Python code?
def foo():
try:
print(1)
finally:
print(2)
foo()
1 2
1
2
None of the above Mentioned
What happens when ‘1’ == 1 is executed?
we get a True
we get a False
an TypeError occurs
a ValueError occurs
Which of the following is not an exception handling keyword in Python?
accept
finally
try
except
What will be the output of the following Python code?
lst = [1, 2, 3]
lst[3]
a) NameError
b) ValueError
c) IndexError
d) TypeError
What will be the output of the following Python code?
lst = [1, 2, 3]
lst[3]
print(t[5])
ValuError
TypeError
IndexError
NameError
What will be the output of the following Python code
print(4 + '3')
TypeError
NameError
IndexError
ValueError
CODE 1
import math
num=int(input("Enter a number of whose factorial you want to find"))
print(math.factorial(num))
Input for CODE 1 is -12
CODE 2
num=int(input("Enter a number of whose factorial you want to find"))
print(math.factorial(num))
Input for CODE 2 is 12
ValueError, NameError
AttributeError, ValueError
NameError, TypeError
TypeError, ValueError
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)
ValueError
ValueError(“Invalid”)
Invalid
6
Which of the following is not a standard exception in Python?
NameError
IOError
AssignmentError
ValueError
Which of the following keyword is optional in Exception handling program
try
except
finally
else
How many except statements can a try-except statement have?
None
One
Two
Multiple
When is the finally block executed?
when an exception occurs
when no exception occurs
never
always
When will the else part of try-except-else be executed?
always
when an exception occurs
when no exception occurs
never
