Exception Handling In Python — Part 1 MCQs with Explanations
Practice high-yield Programming & Software Development MCQs on Exception Handling In Python — Part 1 with worked academic solutions for FPSC, PPSC, NTS, NITB, PTS.
Questions
40
Difficulty Level
Exam-Level
Target Exams
FPSC, PPSC, NTS...
Estimated Time
48 mins
Exam-Level FPSC PPSC NTS NITB PTS
Verified for Commission Syllabus • Oct 14, 2026
40
Verified Practice Questions
Interactive test mode with detailed academic worked solutions
Live Progress|0/40 answered
✓0 correct
✗0 wrong
0% score
🎉 Set complete! All 40 questions answered.
Question 1 of 40
★ FPSC
★ PPSC
★ FPSC
★ PPSC
What is the purpose of exception handling in Python?
Correct Answer: Option A — To handle runtime errors and prevent the program from crashing
Detailed Academic Explanation:
To handle runtime errors and prevent the program from crashing is the correct answer to “What is the purpose of exception handling in Python”. This question is standard in competitive examination syllabi for Exception Handling In Python.
💡Key Conceptual Anchor:Exception Handling In Python
Question 2 of 40
★ FPSC
★ PPSC
★ FPSC
★ PPSC
When is the finally block executed?
Correct Answer: Option D — always
Detailed Academic Explanation:
always is the correct answer to “When is the finally block executed”. This question is standard in competitive examination syllabi for Exception Handling In Python.
💡Key Conceptual Anchor:Exception Handling In Python
Question 3 of 40
★ FPSC
★ PPSC
★ FPSC
★ PPSC
What is an exception in Python?
Correct Answer: Option A — An error that occurs during the execution of a program
Detailed Academic Explanation:
An error that occurs during the execution of a program is the correct answer to “What is an exception in Python”. This question is standard in competitive examination syllabi for Exception Handling In Python.
💡Key Conceptual Anchor:Exception Handling In Python
Question 4 of 40
★ FPSC
★ PPSC
★ FPSC
★ PPSC
How many except statements can a try-except block have?
Correct Answer: Option D — more than zero
Detailed Academic Explanation:
more than zero is the correct answer to “How many except statements can a try-except block have”. This question is standard in competitive examination syllabi for Exception Handling In Python.
💡Key Conceptual Anchor:Exception Handling In Python
Question 5 of 40
★ FPSC
★ PPSC
★ FPSC
★ PPSC
What will happen if an exception is raised in a try block and is not handled in any of the except blocks?
Correct Answer: Option A — The program will terminate with an error message
Detailed Academic Explanation:
The program will terminate with an error message is the correct answer to “What will happen if an exception is raised in a try block and is not handled in any of the except blocks”. This question is standard in competitive examination syllabi for Exception Handling In Python.
💡Key Conceptual Anchor:Exception Handling In Python
Question 6 of 40
★ FPSC
★ PPSC
★ FPSC
★ PPSC
Which built-in Python function can be used to retrieve the error message associated with an exception?
Correct Answer: Option D — exc_info()
Detailed Academic Explanation:
exc_info() is the correct answer to “Which built-in Python function can be used to retrieve the error message associated with an exception”. This question is standard in competitive examination syllabi for Exception Handling In Python.
💡Key Conceptual Anchor:Exception Handling In Python
Question 7 of 40
★ FPSC
★ PPSC
★ FPSC
★ PPSC
When will the else part of try-except-else be executed?
Correct Answer: Option C — when no exception occurs
Detailed Academic Explanation:
when no exception occurs is the correct answer to “When will the else part of try-except-else be executed”. This question is standard in competitive examination syllabi for Exception Handling In Python.
💡Key Conceptual Anchor:Exception Handling In Python
Question 8 of 40
★ FPSC
★ PPSC
★ FPSC
★ PPSC
Can one block of except statements handle multiple exception?
Correct Answer: Option A — yes, like except TypeError, SyntaxError [,...]
Detailed Academic Explanation:
yes, like except TypeError, SyntaxError [,...] is the correct answer to “Can one block of except statements handle multiple exception”. This question is standard in competitive examination syllabi for Exception Handling In Python.
💡Key Conceptual Anchor:Exception Handling In Python
Question 9 of 40
★ FPSC
★ PPSC
★ FPSC
★ PPSC
Which keyword is used to handle exceptions in Python?
Correct Answer: Option A — try
Detailed Academic Explanation:
try is the correct answer to “Which keyword is used to handle exceptions in Python”. This question is standard in competitive examination syllabi for Exception Handling In Python.
💡Key Conceptual Anchor:Exception Handling In Python
Question 10 of 40
★ FPSC
★ PPSC
★ FPSC
★ PPSC
Which of the following statements is true regarding the order of except clauses?
Correct Answer: Option A — The except clauses should be ordered from more specific exceptions to more general ones
Detailed Academic Explanation:
The except clauses should be ordered from more specific exceptions to more general ones is the correct answer to “Which of the following statements is true regarding the order of except clauses”. This question is standard in competitive examination syllabi for Exception Handling In Python.
💡Key Conceptual Anchor:Exception Handling In Python
Question 11 of 40
★ FPSC
★ PPSC
★ FPSC
★ PPSC
What is the purpose of the assert statement in Python?
Correct Answer: Option A — To test if a given condition is True, and if not, raise an AssertionError exception
Detailed Academic Explanation:
To test if a given condition is True, and if not, raise an AssertionError exception is the correct answer to “What is the purpose of the assert statement in Python”. This question is standard in competitive examination syllabi for Exception Handling In Python.
💡Key Conceptual Anchor:Exception Handling In Python
Question 12 of 40
★ FPSC
★ PPSC
★ FPSC
★ PPSC
The following Python code will result in an error if the input value is entered as -5. assert False, 'Spanish'
Correct Answer: Option A — True
Detailed Academic Explanation:
True is the correct answer to “The following Python code will result in an error if the input value is entered as -5. assert False, 'Spanish'”. This question is standard in competitive examination syllabi for Exception Handling In Python.
💡Key Conceptual Anchor:Exception Handling In Python
Question 13 of 40
★ FPSC
★ PPSC
★ FPSC
★ PPSC
What is the purpose of the except clause in a try block?
Correct Answer: Option A — To define the block of code that will be executed if an exception is raised
Detailed Academic Explanation:
To define the block of code that will be executed if an exception is raised is the correct answer to “What is the purpose of the except clause in a try block”. This question is standard in competitive examination syllabi for Exception Handling In Python.
💡Key Conceptual Anchor:Exception Handling In Python
Question 14 of 40
★ FPSC
★ PPSC
★ FPSC
★ PPSC
What is the output of the following code: try: x = 10 / 0 except ZeroDivisionError: print("Error!") finally: print("Finally!")
Correct Answer: Option A — Error! Finally!
Detailed Academic Explanation:
Error! Finally! is the correct answer to “What is the output of the following code: try: x = 10 / 0 except ZeroDivisionError: print("Error!") finally: print("Finally!")”. This question is standard in competitive examination syllabi for Exception Handling In Python.
💡Key Conceptual Anchor:Exception Handling In Python
Question 15 of 40
★ FPSC
★ PPSC
★ FPSC
★ PPSC
Which of the following is not an exception handling keyword in Python?
Correct Answer: Option C — accept
Detailed Academic Explanation:
accept is the correct answer to “Which of the following is not an exception handling keyword in Python”. This question is standard in competitive examination syllabi for Exception Handling In Python.
💡Key Conceptual Anchor:Exception Handling In Python
Question 16 of 40
★ FPSC
★ PPSC
★ FPSC
★ PPSC
What is the purpose of the else clause in a try block?
Correct Answer: Option A — To define the block of code that will be executed if no exception is raised
Detailed Academic Explanation:
To define the block of code that will be executed if no exception is raised is the correct answer to “What is the purpose of the else clause in a try block”. This question is standard in competitive examination syllabi for Exception Handling In Python.
💡Key Conceptual Anchor:Exception Handling In Python
Question 17 of 40
★ FPSC
★ PPSC
★ FPSC
★ PPSC
What is the purpose of the finally clause in a try block?
Correct Answer: Option A — To define the block of code that will always be executed, whether an exception is raised or not
Detailed Academic Explanation:
To define the block of code that will always be executed, whether an exception is raised or not is the correct answer to “What is the purpose of the finally clause in a try block”. This question is standard in competitive examination syllabi for Exception Handling In Python.
💡Key Conceptual Anchor:Exception Handling In Python
Question 18 of 40
★ FPSC
★ PPSC
★ FPSC
★ PPSC
How can you create a custom exception class in Python?
Correct Answer: Option A — By inheriting from the Exception class
Detailed Academic Explanation:
By inheriting from the Exception class is the correct answer to “How can you create a custom exception class in Python”. This question is standard in competitive examination syllabi for Exception Handling In Python.
💡Key Conceptual Anchor:Exception Handling In Python
Question 19 of 40
★ FPSC
★ PPSC
★ FPSC
★ PPSC
What is the syntax to raise an exception manually in Python?
Correct Answer: Option A — raise Exception("Message")
Detailed Academic Explanation:
raise Exception("Message") is the correct answer to “What is the syntax to raise an exception manually in Python”. This question is standard in competitive examination syllabi for Exception Handling In Python.
💡Key Conceptual Anchor:Exception Handling In Python
Question 20 of 40
★ FPSC
★ PPSC
★ FPSC
★ PPSC
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)
Correct Answer: Option C — 6
Detailed Academic Explanation:
6 is the correct answer to “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)”. This question is standard in competitive examination syllabi for Exception Handling In Python.
💡Key Conceptual Anchor:Exception Handling In Python
Question 21 of 40
★ FPSC
★ PPSC
★ FPSC
★ PPSC
What will be the output of the following Python code? def f(x): yield x+1 print("test") yield x+2 g=f(9)
Correct Answer: Option D — No output
Detailed Academic Explanation:
No output is the correct answer to “What will be the output of the following Python code? def f(x): yield x+1 print("test") yield x+2 g=f(9)”. This question is standard in competitive examination syllabi for Exception Handling In Python.
💡Key Conceptual Anchor:Exception Handling In Python
Question 22 of 40
★ FPSC
★ PPSC
★ FPSC
★ PPSC
What happens when '1' == 1 is executed?
Correct Answer: Option B — we get a False
Detailed Academic Explanation:
we get a False is the correct answer to “What happens when '1' == 1 is executed”. This question is standard in competitive examination syllabi for Exception Handling In Python.
💡Key Conceptual Anchor:Exception Handling In Python
Question 23 of 40
★ FPSC
★ PPSC
★ FPSC
★ PPSC
Which of the following is not a standard exception in Python?
Correct Answer: Option C — AssignmentError
Detailed Academic Explanation:
AssignmentError is the correct answer to “Which of the following is not a standard exception in Python”. This question is standard in competitive examination syllabi for Exception Handling In Python.
💡Key Conceptual Anchor:Exception Handling In Python
Question 24 of 40
★ FPSC
★ PPSC
★ FPSC
★ PPSC
Is the following Python code valid? try: # Do something except: # Do something finally: # Do something
Correct Answer: Option D — yes
Detailed Academic Explanation:
yes is the correct answer to “Is the following Python code valid? try: # Do something except: # Do something finally: # Do something”. This question is standard in competitive examination syllabi for Exception Handling In Python.
💡Key Conceptual Anchor:Exception Handling In Python
Question 25 of 40
★ FPSC
★ PPSC
★ FPSC
★ PPSC
What is the purpose of the except clause without specifying an exception type in a try block?
Correct Answer: Option A — To catch any exception that occurs within the try block
Detailed Academic Explanation:
To catch any exception that occurs within the try block is the correct answer to “What is the purpose of the except clause without specifying an exception type in a try block”. This question is standard in competitive examination syllabi for Exception Handling In Python.
💡Key Conceptual Anchor:Exception Handling In Python
Question 26 of 40
★ FPSC
★ PPSC
★ FPSC
★ PPSC
Identify the type of error in the following Python codes? Print(“Good Morning”) print(“Good night)
Correct Answer: Option B — Semantic, Syntax
Detailed Academic Explanation:
Semantic, Syntax is the correct answer to “Identify the type of error in the following Python codes? Print(“Good Morning”) print(“Good night)”. This question is standard in competitive examination syllabi for Exception Handling In Python.
💡Key Conceptual Anchor:Exception Handling In Python
Question 27 of 40
★ FPSC
★ PPSC
★ FPSC
★ PPSC
Which of the following is not a standard Python exception?
Correct Answer: Option A — Error
Detailed Academic Explanation:
Error is the correct answer to “Which of the following is not a standard Python exception”. This question is standard in competitive examination syllabi for Exception Handling In Python.
💡Key Conceptual Anchor:Exception Handling In Python
Question 28 of 40
★ FPSC
★ PPSC
★ FPSC
★ PPSC
What is the purpose of the sys.exc_info() function in Python?
Correct Answer: Option A — It returns information about the currently handled exception
Detailed Academic Explanation:
It returns information about the currently handled exception is the correct answer to “What is the purpose of the sys.exc_info() function in Python”. This question is standard in competitive examination syllabi for Exception Handling In Python.
💡Key Conceptual Anchor:Exception Handling In Python
Question 29 of 40
★ FPSC
★ PPSC
★ FPSC
★ PPSC
What will be the output of the following Python code? g = (i for i in range(5)) type(g)
Correct Answer: Option D — class <'generator'>
Detailed Academic Explanation:
class <'generator'> is the correct answer to “What will be the output of the following Python code? g = (i for i in range(5)) type(g)”. This question is standard in competitive examination syllabi for Exception Handling In Python.
💡Key Conceptual Anchor:Exception Handling In Python
Question 30 of 40
★ FPSC
★ PPSC
★ FPSC
★ PPSC
How can you catch and handle multiple exceptions in a single except block in Python?
Correct Answer: Option A — By enclosing the exceptions in parentheses and separating them with commas
Detailed Academic Explanation:
By enclosing the exceptions in parentheses and separating them with commas is the correct answer to “How can you catch and handle multiple exceptions in a single except block in Python”. This question is standard in competitive examination syllabi for Exception Handling In Python.
💡Key Conceptual Anchor:Exception Handling In Python
Question 31 of 40
★ FPSC
★ PPSC
★ FPSC
★ PPSC
What will be the output of the following Python code? def foo(): try: print(1) finally: print(2) foo()
Correct Answer: Option A — 1 2
Detailed Academic Explanation:
1 2 is the correct answer to “What will be the output of the following Python code? def foo(): try: print(1) finally: print(2) foo()”. This question is standard in competitive examination syllabi for Exception Handling In Python.
💡Key Conceptual Anchor:Exception Handling In Python
Question 32 of 40
★ FPSC
★ PPSC
★ FPSC
★ PPSC
What will be the output of the following Python code? int('65.43')
Correct Answer: Option B — ValueError
Detailed Academic Explanation:
ValueError is the correct answer to “What will be the output of the following Python code? int('65.43')”. This question is standard in competitive examination syllabi for Exception Handling In Python.
💡Key Conceptual Anchor:Exception Handling In Python
Question 33 of 40
★ FPSC
★ PPSC
★ FPSC
★ PPSC
An exception is . . . . . . . .
Correct Answer: Option A — an object
Detailed Academic Explanation:
an object is the correct answer to “An exception is . . . . . . . .”. This question is standard in competitive examination syllabi for Exception Handling In Python.
💡Key Conceptual Anchor:Exception Handling In Python
Question 34 of 40
★ FPSC
★ PPSC
★ FPSC
★ PPSC
What will be the output of the following Python code? def f(x): yield x+1 print("test") yield x+2 g=f(10) print(next(g)) print(next(g))
Correct Answer: Option B — 11 12
Detailed Academic Explanation:
11 12 is the correct answer to “What will be the output of the following Python code? def f(x): yield x+1 print("test") yield x+2 g=f(10) print(next(g)) print(next(g))”. This question is standard in competitive examination syllabi for Exception Handling In Python.
💡Key Conceptual Anchor:Exception Handling In Python
Question 35 of 40
★ FPSC
★ PPSC
★ FPSC
★ PPSC
Compare the following two Python codes shown below and state the output if the input entered in each case is -6? CODE 1 import math num=int(input("Enter a number of whose factorial you want to find")) print(math.factorial(num)) CODE 2 num=int(input("Enter a number of whose factorial you want to find")) print(math.factorial(num))
Correct Answer: Option A — ValueError, NameError
Detailed Academic Explanation:
ValueError, NameError is the correct answer to “Compare the following two Python codes shown below and state the output if the input entered in each case is -6? CODE 1 import math num=int(input("Enter a number of whose factorial you want to find")) print(math.factorial(num)) CODE 2 num=int(input("Enter a number of whose factorial you want to find")) print(math.factorial(num))”. This question is standard in competitive examination syllabi for Exception Handling In Python.
💡Key Conceptual Anchor:Exception Handling In Python
Question 36 of 40
★ FPSC
★ PPSC
★ FPSC
★ PPSC
What will be the output of the following Python code? lst = [1, 2, 3] lst[3]
Correct Answer: Option C — IndexError
Detailed Academic Explanation:
IndexError is the correct answer to “What will be the output of the following Python code? lst = [1, 2, 3] lst[3]”. This question is standard in competitive examination syllabi for Exception Handling In Python.
💡Key Conceptual Anchor:Exception Handling In Python
Question 37 of 40
★ FPSC
★ PPSC
★ FPSC
★ PPSC
What will be the output of the following Python code? def a(): try: f(x, 4) finally: print('after f') print('after f?') a()
Correct Answer: Option C — error
Detailed Academic Explanation:
error is the correct answer to “What will be the output of the following Python code? def a(): try: f(x, 4) finally: print('after f') print('after f?') a()”. This question is standard in competitive examination syllabi for Exception Handling In Python.
💡Key Conceptual Anchor:Exception Handling In Python
Question 38 of 40
★ FPSC
★ PPSC
★ FPSC
★ PPSC
What will be the output of the following Python code? x=10 y=8 assert x>y, 'X too small'
Correct Answer: Option C — No output
Detailed Academic Explanation:
No output is the correct answer to “What will be the output of the following Python code? x=10 y=8 assert x>y, 'X too small'”. This question is standard in competitive examination syllabi for Exception Handling In Python.
💡Key Conceptual Anchor:Exception Handling In Python
Question 39 of 40
★ FPSC
★ PPSC
★ FPSC
★ PPSC
What will be the output of the following Python code? #generator def f(x): yield x+1 g=f(8) print(next(g))
Correct Answer: Option B — 9
Detailed Academic Explanation:
9 is the correct answer to “What will be the output of the following Python code? #generator def f(x): yield x+1 g=f(8) print(next(g))”. This question is standard in competitive examination syllabi for Exception Handling In Python.
💡Key Conceptual Anchor:Exception Handling In Python
Question 40 of 40
★ FPSC
★ PPSC
★ FPSC
★ PPSC
What will be the output of the following Python code if the input entered is 6? valid = False while not valid: try: n=int(input("Enter a number")) while n%2==0: print("Bye") valid = True except ValueError: print("Invalid")
Correct Answer: Option D — Bye (printed infinite number of times)
Detailed Academic Explanation:
Bye (printed infinite number of times) is the correct answer to “What will be the output of the following Python code if the input entered is 6? valid = False while not valid: try: n=int(input("Enter a number")) while n%2==0: print("Bye") valid = True except ValueError: print("Invalid")”. This question is standard in competitive examination syllabi for Exception Handling In Python.
💡Key Conceptual Anchor:Exception Handling In Python
✓Link copied to clipboard
Continue Your Practice
Advance Html — Part 1
Master the next curriculum module with 40 exam-standard MCQs.
💡Examiner's Advisory for Programming & Software Development
In competitive commission exams (FPSC, PPSC, KPPSC, SPSC, CSS, PMS), questions are frequently phrased with distractor options designed to catch rote learners. Whenever you answer an MCQ, read the Detailed Academic Explanation and Conceptual Anchor to understand why the remaining options are incorrect.