I came across the need to do this:
try:
prop_file = next(file for file in os.listdir(data_folder) if 'property' in file)
except StopIteration:
raise StopIteration('The property file could not be found in the specified folder ({})!'.format(data_folder))
which seems kinda silly because I am catching an exception only to re-throw it but this time with a more information-rich feedback.
Are there alternatives to this, or is this considered a standard practice?
StopIteration, and moderately unusual to explicitly throwStopIterationat all. In the normal cases where Python catchesStopIteration, the argument isn't even treated as an exception message; it's used as the expression value for ayield fromexpression.