Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Avoid bare try-except #1407

Open
dhalbert opened this issue Jan 11, 2021 · 0 comments
Open

Avoid bare try-except #1407

dhalbert opened this issue Jan 11, 2021 · 0 comments

Comments

@dhalbert
Copy link
Contributor

dhalbert commented Jan 11, 2021

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:

try:
wave_file = open('sounds/' + name + '.wav', 'rb')
wave = audioio.WaveFile(wave_file)
AUDIO.play(wave, loop=loop)
except:
return
.

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.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant