File tree Expand file tree Collapse file tree 1 file changed +8
-2
lines changed
Expand file tree Collapse file tree 1 file changed +8
-2
lines changed Original file line number Diff line number Diff line change @@ -326,7 +326,10 @@ def read_file(file_path):
326326 data = file.read()
327327 return data
328328 except FileNotFoundError:
329- raise FileNotFoundError(f"Oops! I couldn't find the file located at: {file_path}. Please check to see if it exists.")
329+ raise FileNotFoundError(
330+ f"Oops! I couldn't find the file located at: {file_path}. "
331+ "Please check to see if it exists."
332+ ) # no "from" statement implicitly chains the prior error
330333
331334
332335file_data = read_file("nonexistent_file.txt")
@@ -345,7 +348,10 @@ def read_file(file_path):
345348 data = file.read()
346349 return data
347350 except FileNotFoundError:
348- raise FileNotFoundError(f"Oops! I couldn't find the file located at: {file_path}. Please check to see if it exists.") from None
351+ raise FileNotFoundError(
352+ f"Oops! I couldn't find the file located at: {file_path}. "
353+ "Please check to see if it exists."
354+ ) from None # explicitly break the exception chain
349355
350356
351357file_data = read_file("nonexistent_file.txt")
You can’t perform that action at this time.
0 commit comments