i want to raise ConnectionError (a python 3 subclass) when my program fails to connect to a local service. i'm using python2.7. testing this out though, it looks like i have to import a module to get this working:
>>> raise ConnectionError("test")
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
NameError: name 'ConnectionError' is not defined
how can i raise this type of exception?
ConnectionError does not exist in Python 2, as you can see from the Python 2 documentation. You can of course create your own subclass of OSError (and even call it ConnectionError if you want), but no such thing is built in.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With