Loading

Quipoin Menu

Learn • Practice • Grow

python / Exception Handling
mcq
Direction: Choose the correct option

Q1.

What is the syntax for a try-except block?
A. try: ... except: ...
B. try: ... finally: ...
C. try: ... error: ...
D. try: ... catch: ...
Direction: Choose the correct option

Q2.

What does the `except` block catch?
A. Only runtime errors
B. Exceptions raised in the try block
C. Only syntax errors
D. All errors
Direction: Choose the correct option

Q3.

How do you catch a specific exception type?
A. except Exception as e:
B. except value error:
C. except ValueError:
D. except:
Direction: Choose the correct option

Q4.

What is the purpose of the `else` clause in a try-except?
A. Executes if exception occurs
B. Always executes
C. Executes if no exception occurs
D. Executes after finally
Direction: Choose the correct option

Q5.

What does the `finally` clause do?
A. Executes before try
B. Always executes, regardless of exception
C. Executes only if no exception
D. Executes only if exception occurs
Direction: Choose the correct option

Q6.

What is the base class for all built-in exceptions?
A. ArithmeticError
B. BaseException
C. RuntimeError
D. Exception
Direction: Choose the correct option

Q7.

How do you raise an exception manually?
A. throw Exception
B. raise Exception
C. throw ValueError('error')
D. raise ValueError('error')
Direction: Choose the correct option

Q8.

What happens if an exception is not caught?
A. Program terminates and prints traceback
B. Program continues
C. Exception is stored
D. Error is ignored
Direction: Choose the correct option

Q9.

How do you get the error message from an exception?
A. except: print(e)
B. except Exception as e: print(e)
C. except Exception: print(e)
D. except: print(error)
Direction: Choose the correct option

Q10.

What is the output of `try: x = 1/0; except ZeroDivisionError: print('error')`?
A. nothing
B. 1
C. ZeroDivisionError
D. error