Обложка канала

Библиотека Python разработчика

20835 @BookPython

Библиотека Python разработчика. Книги по программированию на Python.

Библиотека Python разработчика

4 года назад
Открыть в
Sometimes you want to run a piece of code and ignore all exceptions that it may raise. It's reasonable for plugins, foreign modules, and other units you don't understand nor trust. The proper way to do this is to use try with except Exception, not bare except: try: foreign() except Exception: logging.warn('fail', exc_info=True) except without explicit exception type is an equivalent for except BaseException. The difference between BaseException and Exception is that the former includes exceptions you usually don't want to such as KeyboardInterrupt. @BookPython