CARVIEW |
Error Handling, File Handling and Advanced Techniques
Error Handling, File Handling and Advanced Techniques
Question 1
How can you handle uncaught exceptions globally in Python?
By defining a custom global exception handler function and assigning it to sys.excepthook
Using the 'global_exception_handler()' function
By using the 'global' keyword
There is no way to handle exceptions globally
Question 2
In Python, what does the sys.exc_info() function return?
The exception type
The exception value
A tuple containing the exception type, value, and traceback
A dictionary containing exception information
Question 3
What is the purpose of the raise statement in Python?
To raise an arbitrary exception
To terminate the program
To catch an exception
To ignore an exception
Question 4
What will happen if an exception is raised but not caught in a Python program?
The program will terminate abruptly
The program will continue to execute without any impact
The program will print an error message and continue
The program will prompt the user to handle the exception
Question 5
How can you re-raise an exception in Python?
Using the retry statement
Using the throw statement
Using the raise statement without any arguments
Using the rethrow keyword
Question 7
How can you read a specific line containing a keyword from a file in Python?
file.read_line_with_keyword(keyword)
read_line_with_keyword(file, keyword)
file.read_line(keyword)
read_keyword_line(file, keyword)
Question 8
Which function is used to open a file in Python?
open_file()
read_file()
file_open()
open()
Question 9
What is the output of the following code snippet?
with open("data.txt", "r") as file:
content = file.read()
print(content)
Prints the content of "data.txt"
Raises a FileNotFoundError
Prints "None"
Raises a PermissionError
Question 10
What does the following code snippet do?
with open("file.txt", "a") as file:
file.write("New data")
Reads the content of "file.txt"
Appends "New data" to "file.txt"
Creates a new file "file.txt"
Replaces the content of "file.txt" with "New data"
There are 24 questions to complete.