Skip to content

Commit 47587fe

Browse files
sneakers-the-ratlwasser
authored andcommitted
linebreaks to actually be able to see the error chaining
1 parent 95da92d commit 47587fe

File tree

1 file changed

+8
-2
lines changed

1 file changed

+8
-2
lines changed

code-workflow-logic/python-function-checks.md

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff 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
332335
file_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
351357
file_data = read_file("nonexistent_file.txt")

0 commit comments

Comments
 (0)