Catch Exception, instead of BaseException or using bare except: clauses.
This is still very broad, but avoids the case of catching SystemExit or KeyboardInterrupt (which are not subclasses of Exception) and re-raising them as ConnectionError.
Application code may handle ConnectionErrors differently (such as attempting re-connection) to SystemExit or KeyboardInterrupt, which may be raised in signal handlers and which the application may treat as a relatively normal shutdown.
Catch
Exception
, instead ofBaseException
or using bareexcept:
clauses.This is still very broad, but avoids the case of catching
SystemExit
orKeyboardInterrupt
(which are not subclasses ofException
) and re-raising them asConnectionError
.Application code may handle
ConnectionError
s differently (such as attempting re-connection) toSystemExit
orKeyboardInterrupt
, which may be raised in signal handlers and which the application may treat as a relatively normal shutdown.