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
1. What type of errors are exceptions in Python?
2. What happens when a syntax error occurs in Python?
3. What are syntax errors also known as?
4. Which Python mode provides immediate feedback on syntax errors?
5. When does a ZeroDivisionError occur?
6. What does Python do when an exception is raised during execution?
7. Which exception is raised when a variable is not defined?
8. What does the IOError exception indicate?
9. Which exception is raised for incorrect indentation?
10. Which keyword is used to manually raise an exception?
11. What happens after an exception is raised using the raise statement?
12. What exception does the assert statement raise if the condition is False?
13. What is the main purpose of exception handling?
14. Which block is used to catch exceptions in Python?
15. Which block is always executed, irrespective of whether an exception occurred?
16. What happens if multiple except blocks are present for a single try block?
17. When is the else clause executed in a try…except block?
18. Which block comes immediately after the try block?
19. What is the primary use of the finally block?
20. Which statement is true for the finally block?
21. Which exception is handled in the following code? try: num = int(input("Enter a number: ")) except ValueError: print("Invalid input!")
22. What happens if no exception is raised in the try block? try: num = int(input("Enter a number: ")) except ValueError: print("Invalid input!")
23. What will happen if an exception not matched by any except block occurs?
24. In a try…except block with multiple except clauses, which block is executed first?
25. What can be included in the raise statement for additional information?
26. What does the following code output? try: raise ValueError("Custom error message") except ValueError as e: print(e)
27. Which exception is user-defined?
28. What is printed by the following code? try: raise NameError("Example") except NameError: print("NameError occurred")
29. Which exception does an assert statement raise if the expression is False?
30. What happens if the assert condition evaluates to True?
31. What does the runtime system do when an exception occurs?
32. What happens if no handler is found in the call stack?
33. What does the following code do? try: x = 1 / 0 except ZeroDivisionError: print("Cannot divide by zero!")
34. Which statement is valid for catching exceptions?
35. What is the output of the following code? try: print(1 / 0) except ZeroDivisionError: print("Exception handled") finally: print("Finally block executed")
36. Which block will execute even if an exception is not raised?
37. What is the purpose of a generic except block?
38. Which block is recommended for cleanup operations?
39. What does the following code print? try: int("abc") except ValueError: print("ValueError handled")
40. What happens when an exception is raised but not caught?
41. What is the purpose of an else clause in a try block?
42. Which block can have more than one occurrence in exception handling?
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.")
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!")
45. What does exception handling ensure?
46. What is the primary benefit of a try…finally structure?
47. What exception is raised if input() encounters EOF?
48. When is the OverFlowError raised?
49. What is the process of finding an exception handler called?
50. What happens when an exception is successfully caught?
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.
52. Assertion (A): Exceptions disrupt the normal flow of program execution. Reason (R): Exceptions represent errors that occur during runtime and must be handled.
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.
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.
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.
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.
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.
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.
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.
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.
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.
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.
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.
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.
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.
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.
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.
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.
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.
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.
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.
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.
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.
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.
75. Assertion (A): Exception handling improves program robustness and user experience. Reason (R): Exception handling prevents programs from crashing abruptly during runtime errors.

No comments: