I work through Python tutorial and ran against a sample in https://docs.python.org/3/tutorial/errors.html in section 8.9. Raising and Handling Multiple Unrelated Exceptions which doesn't work by me:
$ python
Python 3.10.12 (main, Jun 11 2023, 05:26:28) [GCC 11.4.0] on linux
Type "help", "copyright", "credits" or "license" for more information.
>>> excs = [OSError('error 1'), SystemError('error 2')]
>>> raise ExceptionGroup('there were problems', excs)
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
NameError: name 'ExceptionGroup' is not defined
>>>
Why? Isn't a ExceptionGroup
a built-in exception? The compiler doesn't give any errors and IDE pops up the documentation for this class...
The next thought was - I have to import something:
>>> from builtins import ExceptionGroup
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
ImportError: cannot import name 'ExceptionGroup' from 'builtins' (unknown location)
What's wrong?
According to the official docs, ExceptionGroup was only added in Python 3.11. Make sure you check your Python version
Collected from the Internet
Please contact [email protected] to delete if infringement.
Comments