Metadata

ID: python-best-practices/no-generic-exception

Language: Python

Severity: Warning

Category: Best Practices

Description

The specific error must be raised, not a generic Exception. Use the exact exception(s) you want to handle and have a recovery handler for each exception that your program may raise.

Learn More

Non-Compliant Code Examples

a = 2
b = 0
try:
  c = a /b
except Exception as e:
  pass

Compliant Code Examples

a = 2
b = 0
try:
  c = a /b
except ValueError as e:
  pass