Adafruit_Learning_System_Guides
Adafruit_Learning_System_Guides copied to clipboard
Avoid bare try-except
A number of examples here have code like:
try:
# something that might fail
except:
return # or pass or something like that
Sometimes there's good reason for a "bare except", but a lot of times it could hide an unexpected error. It's better to list the expected exceptions explicitly [how's that for alliteration?]. An example is: https://github.com/adafruit/Adafruit_Learning_System_Guides/blob/4879082f54df6728f5e8787fc1417e407c1d466e/Hallowing_Lightsaber/lightsaber_standard.py#L52-L57.
I think this might have meant to catch missing audio files, but it started catching audioio.WaveFile() failure (because now it's audiocore.WaveFile().) and not complaining. This made the failure non-obvious to an experienced user in the forums.