Cette page n'est pas encore disponible en français, sa traduction est en cours. Si vous avez des questions ou des retours sur notre projet de traduction actuel, n'hésitez pas à nous contacter.
Metadata
ID:python-best-practices/no-bare-except
Language: Python
Severity: Warning
Category: Best Practices
Description
Avoid bare except. Try to always use specialized exception names in except blocks.
Non-Compliant Code Examples
try:print("foo")except:# use a specialized exception nameprint("bar")
Compliant Code Examples
try:parsed=json.loads(response.body)exceptjson.JSONDecodeError:log.warning("Test skips request responded with invalid JSON '%s'",response.body)return