Skip to content

Instantly share code, notes, and snippets.

@brun0xff
Last active July 4, 2018 20:50
Show Gist options
  • Select an option

  • Save brun0xff/be8dc463f74fd8222a73084dcb36f28a to your computer and use it in GitHub Desktop.

Select an option

Save brun0xff/be8dc463f74fd8222a73084dcb36f28a to your computer and use it in GitHub Desktop.

Uma boa prática é ao capturar exceções, mencionar sempre que possível as exceções específicas, em vez de usar apenas except Exception. Exemplo:

try:
    import platform_specific_module
except ImportError:
    platform_specific_module = None

Dá uma olhada:

A good rule of thumb is to limit use of bare 'except' clauses to two cases:

1. If the exception handler will be printing out or logging the traceback; at least the user will be aware that an error has occurred. 2. If the code needs to do some cleanup work, but then lets the exception propagate upwards with raise. try...finally can be a better way to handle this case.

Fonte: https://www.python.org/dev/peps/pep-0008/?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment