CHAPTER 1 EXCEPTION HANDLING IN PYTHON
MULTIPLE
CHOICE
QUESTIONS
(MCQs)
1.
What type of errors are exceptions in Python?
a) Logical errors b) Syntax errors c) Runtime errors d) Parsing errors
2.
What happens when a syntax error occurs in Python?
a) Program continues with incorrect output b) Program halts with a description of the error
c) Program fixes the error automatically d) Program warns but does not stop
3.
What are syntax errors also known as?
a) Runtime errors b) Logical errors c) Parsing errors d) None of the above
4.
Which Python mode provides immediate feedback on syntax errors?
a) Script mode b) Shell mode c) IDE mode d) Debug mode
5.
When does a ZeroDivisionError occur?
a) Dividing by a negative number b) Using a zero numerator
c) Dividing by zero d) Using zero in mathematical expressions
6.
What does Python do when an exception is raised during execution?
a) Continues execution b) Skips the error c) Terminates the program abruptly
d) Jumps to exception handling code if present
7.
Which exception is raised when a variable is not defined?
a) NameError b) ValueError c) SyntaxError d) TypeError
8.
What does the IOError exception indicate?
a) An undefined variable b) A file that cannot be opened
c) A division by zero d) An incorrect argument type
9.
Which exception is raised for incorrect indentation?
a) ValueError b) TypeError c) IndentationError d) SyntaxError
10.
Which keyword is used to manually raise an exception?
a) assert b) raise c) throw d) except
11.
What happens after an exception is raised using the raise statement?
a) The remaining statements in the block are executed b) The current block stops execution
c) Execution continues in the same block d) None of the above
12.
What exception does the assert statement raise if the condition is False?
a) AssertionError b) ValueError c) SyntaxError d) RuntimeError
13.
What is the main purpose of exception handling?
a) To debug syntax errors b) To prevent program crashes
c) To increase execution speed d) To optimize performance
14.
Which block is used to catch exceptions in Python?
a) try b) except c) else d) finally
15.
Which block is always executed, irrespective of whether an exception occurred?
a) try b) except c) else d) finally
16.
What happens if multiple except blocks are present for a single try block?
a) All are executed b) The first matching block is executed
c) None are executed d) Only the last block is executed