google.com, pub-6167773875660516, DIRECT, f08c47fec0942fa0 Exception Handling In Python Class 12 Mcq | Mcq On Exception Handling In Python - 2nd puc computer science

Exception Handling In Python Class 12 Mcq | Mcq On Exception Handling In Python

exception handling in python class 12 mcq,mcq on exception handling in python,exception handling in python mcq,exception handling in python mcq questions,exception handling in python class 12 questions and answers,exception handling in python mcq questions,exception handling in python mcq,Exception handling in python class 12 mcq with answers

Exception Handling In Python Class 12 Mcq

1. What type of errors are exceptions in Python?





ANSWER= C) Runtime errors

2. What happens when a syntax error occurs in Python?





ANSWER= B) Program halts with a description of the error

3. What are syntax errors also known as?





ANSWER= C) Parsing errors

4. Which Python mode provides immediate feedback on syntax errors?





ANSWER= B) Shell mode

5. When does a ZeroDivisionError occur?





ANSWER= C) Dividing by zero

6. What does Python do when an exception is raised during execution?





ANSWER= D) Jumps to exception handling code if present

7. Which exception is raised when a variable is not defined?





ANSWER= A) NameError

8. What does the IOError exception indicate?





ANSWER= B) A file that cannot be opened

9. Which exception is raised for incorrect indentation?





ANSWER= C) IndentationError

10. Which keyword is used to manually raise an exception?





ANSWER= B) raise

11. What happens after an exception is raised using the raise statement?





ANSWER= B) The current block stops execution

12. What exception does the assert statement raise if the condition is False?





ANSWER= A) AssertionError

13. What is the main purpose of exception handling?





ANSWER= B) To prevent program crashes

14. Which block is used to catch exceptions in Python?





ANSWER= B) except

15. Which block is always executed, irrespective of whether an exception occurred?





ANSWER= D) finally

16. What happens if multiple except blocks are present for a single try block?





ANSWER= B) The first matching block is executed

17. When is the else clause executed in a try…except block?





ANSWER= A) If no exception occurs

18. Which block comes immediately after the try block?





ANSWER= A) except

19. What is the primary use of the finally block?





ANSWER= B) To execute cleanup code

20. Which statement is true for the finally block?





ANSWER= C) It executes regardless of exceptions

21. Which exception is handled in the following code? try: num = int(input("Enter a number: ")) except ValueError: print("Invalid input!")





ANSWER= C) ValueError

22. What happens if no exception is raised in the try block? try: num = int(input("Enter a number: ")) except ValueError: print("Invalid input!")





ANSWER= B) The else block executes

23. What will happen if an exception not matched by any except block occurs?





ANSWER= B) The program terminates

24. In a try…except block with multiple except clauses, which block is executed first?





ANSWER= B) The most specific matching block

25. What can be included in the raise statement for additional information?





ANSWER= B) Optional arguments like a string message

26. What does the following code output? try: raise ValueError("Custom error message") except ValueError as e: print(e)





ANSWER= C) “Custom error message”

27. Which exception is user-defined?





ANSWER= D) Any exception created by the programmer

28. What is printed by the following code? try: raise NameError("Example") except NameError: print("NameError occurred")





ANSWER= B) NameError occurred

29. Which exception does an assert statement raise if the expression is False?





ANSWER= C) AssertionError

30. What happens if the assert condition evaluates to True?





ANSWER= C) Execution continues

31. What does the runtime system do when an exception occurs?





ANSWER= B) Searches for a handler in the call stack

32. What happens if no handler is found in the call stack?





ANSWER= A) The program terminates

33. What does the following code do? try: x = 1 / 0 except ZeroDivisionError: print("Cannot divide by zero!")





ANSWER= A) Prints “Cannot divide by zero!”

34. Which statement is valid for catching exceptions?





ANSWER= B) try block can have multiple except blocks

35. What is the output of the following code? try: print(1 / 0) except ZeroDivisionError: print("Exception handled") finally: print("Finally block executed")





ANSWER= A) Exception handled Finally block executed

36. Which block will execute even if an exception is not raised?





ANSWER= C) finally

37. What is the purpose of a generic except block?





ANSWER= B) Handle errors not specifically caught

38. Which block is recommended for cleanup operations?





ANSWER= C) finally

39. What does the following code print? try: int("abc") except ValueError: print("ValueError handled")





ANSWER= C) ValueError handled

40. What happens when an exception is raised but not caught?





ANSWER= A) The program terminates

41. What is the purpose of an else clause in a try block?





ANSWER= B) Executes if no exception occurs

42. Which block can have more than one occurrence in exception handling?





ANSWER= B) except

43. What is the output of the following code if the input is 0? try: result = 50 / int(input("Enter a number: ")) except ZeroDivisionError: print("Cannot divide by zero!") except ValueError: print("Invalid input!") finally: print("Execution complete.")





ANSWER= A) Cannot divide by zero! Execution complete.

44. Which exception is raised if the following code is executed and the input is abc? try: num = int(input("Enter a number: ")) except ValueError: print("Invalid input!")





ANSWER= A) ValueError

45. What does exception handling ensure?





ANSWER= C) Program does not crash abruptly

46. What is the primary benefit of a try…finally structure?





ANSWER= B) Clean termination or recovery

47. What exception is raised if input() encounters EOF?





ANSWER= B) EOFError

48. When is the OverFlowError raised?





ANSWER= C) A calculation exceeds the max limit for a numeric type

49. What is the process of finding an exception handler called?





ANSWER= C) Searching the call stack

50. What happens when an exception is successfully caught?





ANSWER= C) Control resumes after the try block

51. Assertion (A): Syntax errors are detected during the execution of a Python program. Reason (R): Syntax errors occur when the rules of the programming language are violated.





ANSWER= C) (A) is true, but (R) is false.

52. Assertion (A): Exceptions disrupt the normal flow of program execution. Reason (R): Exceptions represent errors that occur during runtime and must be handled.





ANSWER= A) Both Assertion (A) and Reason (R) are true, and (R) is the correct explanation of (A).

53. Assertion (A): Built-in exceptions in Python handle commonly occurring errors. Reason (R): Programmers need to create user-defined exceptions for all error cases.





ANSWER= C) (A) is true, but (R) is false.

54. Assertion (A): A ZeroDivisionError is raised when a division operation involves a denominator of zero. Reason (R): Python checks for runtime errors during program execution.





ANSWER= A) Both Assertion (A) and Reason (R) are true, and (R) is the correct explanation of (A).

55. Assertion (A): The raise statement in Python can be used to manually raise exceptions. Reason (R): The raise statement forces an exception to be raised and handled.





ANSWER= A) Both Assertion (A) and Reason (R) are true, and (R) is the correct explanation of (A).

56. Assertion (A): The assert statement raises an exception if the given condition is false. Reason (R): The assert statement is used for debugging and testing in Python.





ANSWER= A) Both Assertion (A) and Reason (R) are true, and (R) is the correct explanation of (A).

57. Assertion (A): The try block must be followed by at least one except block. Reason (R): The try block allows execution of code that may raise exceptions, while the except block handles them.





ANSWER= A) Both Assertion (A) and Reason (R) are true, and (R) is the correct explanation of (A).

58. Assertion (A): The finally block is executed only when an exception is raised in the try block. Reason (R): The finally block ensures cleanup code is executed regardless of whether an exception occurred or not.





ANSWER= D) (A) is false, but (R) is true.

59. Assertion (A): Multiple except blocks can be used for a single try block. Reason (R): Each except block handles a specific type of exception.





ANSWER= A) Both Assertion (A) and Reason (R) are true, and (R) is the correct explanation of (A).

60. Assertion (A): The else block in a try...except structure executes only if no exception occurs in the try block. Reason (R): The else block is executed before the finally block.





ANSWER= A) Both Assertion (A) and Reason (R) are true, and (R) is the correct explanation of (A).

61. Assertion (A): If an exception is not caught in the except block, the program terminates. Reason (R): Unhandled exceptions propagate up the call stack until a handler is found.





ANSWER= A) Both Assertion (A) and Reason (R) are true, and (R) is the correct explanation of (A).

62. Assertion (A): A ValueError is raised when an invalid data type is passed to a function or operation. Reason (R): The ValueError exception occurs for both invalid data types and invalid values.





ANSWER= C) (A) is true, but (R) is false.

63. Assertion (A): The raise statement can be used to throw both built-in and user-defined exceptions. Reason (R): The raise statement interrupts the normal flow of the program and jumps to the exception handler.





ANSWER= A) Both Assertion (A) and Reason (R) are true, and (R) is the correct explanation of (A).

64. Assertion (A): The assert statement allows developers to write test conditions directly in the code. Reason (R): If the condition in an assert statement evaluates to False, an AssertionError is raised.





ANSWER= A) Both Assertion (A) and Reason (R) are true, and (R) is the correct explanation of (A).

65. Assertion (A): The try block handles exceptions, while the except block identifies exceptions. Reason (R): The try block contains code that might raise exceptions, while the except block defines handlers for exceptions.





ANSWER= D) (A) is false, but (R) is true.

66. Assertion (A): An EOFError is raised when the input() function reaches the end of a file without receiving any input. Reason (R): The EOFError occurs when the Python program encounters an empty input stream unexpectedly.





ANSWER= A) Both Assertion (A) and Reason (R) are true, and (R) is the correct explanation of (A).

67. Assertion (A): The finally block is executed even if an unhandled exception occurs in the try block. Reason (R): The finally block is designed to perform cleanup operations regardless of the program’s state.





ANSWER= A) Both Assertion (A) and Reason (R) are true, and (R) is the correct explanation of (A).

68. Assertion (A): The Python interpreter automatically searches the call stack to find an appropriate exception handler when an exception is raised. Reason (R): If an exception handler is not found in the call stack, the program terminates with a traceback.





ANSWER= A) Both Assertion (A) and Reason (R) are true, and (R) is the correct explanation of (A).

69. Assertion (A): The TypeError exception is raised when an operation is applied to an object of an inappropriate type. Reason (R): Python performs type-checking at runtime for all operations.





ANSWER= A) Both Assertion (A) and Reason (R) are true, and (R) is the correct explanation of (A).

70. Assertion (A): A generic except block can be used to catch any exception that is not explicitly named in previous except blocks. Reason (R): A generic except block should always be placed after all specific except blocks to avoid masking exceptions.





ANSWER= A) Both Assertion (A) and Reason (R) are true, and (R) is the correct explanation of (A).

71. Assertion (A): The try...except...else structure ensures that the else block is executed only if the try block executes without raising an exception. Reason (R): The else block in exception handling is useful for executing code that must run only when no exceptions occur.





ANSWER= A) Both Assertion (A) and Reason (R) are true, and (R) is the correct explanation of (A).

72. Assertion (A): The NameError exception is raised when a variable is referenced before it is defined. Reason (R): Undefined variables in Python automatically default to None.





ANSWER= C) (A) is true, but (R) is false.

73. Assertion (A): Exception handling in Python can be applied to both built-in and user-defined exceptions. Reason (R): Python provides the raise statement to throw exceptions and the try...except block to handle them.





ANSWER= A) Both Assertion (A) and Reason (R) are true, and (R) is the correct explanation of (A).

74. Assertion (A): The IndentationError exception is raised when code is not properly indented in Python. Reason (R): Python enforces indentation as part of its syntax for defining blocks of code.





ANSWER= A) Both Assertion (A) and Reason (R) are true, and (R) is the correct explanation of (A).

75. Assertion (A): Exception handling improves program robustness and user experience. Reason (R): Exception handling prevents programs from crashing abruptly during runtime errors.





ANSWER= A) Both Assertion (A) and Reason (R) are true, and (R) is the correct explanation of (A).

Exception Handling In Python Class 12 Mcq | Mcq On Exception Handling In Python Exception Handling In Python Class 12 Mcq | Mcq On Exception Handling In Python Reviewed by Vision Academy on July 06, 2025 Rating: 5

No comments:

CheckOut

Powered by Blogger.