Consider a program that possesses a function that reads information from a file,
ID: 3916231 • Letter: C
Question
Consider a program that possesses a function that reads information from a file, called read_file(). The read file function normally intends to return a list containing pieces of information from the file that is read. If the file reading fails (i.e. raises an exception), what should the read information function do? A. B. C. D. E. Catch the exception and return None in the finally clause. Catch the exception and print a message in the finally clause. Do nothing (don't catch the exception) Catch the exception and print a message in the except clause. Catch the exception and return None in the except clause.Explanation / Answer
Answer: Option D: Catch the exception and print the message in the Except clause.
Explanation:
When the reading fails in python, it will raise an exception (most of the case, it will throw IOException).
We should handle it in Except and print the error message.
Related Questions
Hire Me For All Your Tutoring Needs
Integrity-first tutoring: clear explanations, guidance, and feedback.
Drop an Email at
drjack9650@gmail.com
drjack9650@gmail.com
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.