Follow

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use
Contact

NameError: name 'ExceptionGroup' is not defined

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:

MEDevel.com: Open-source for Healthcare and Education

Collecting and validating open-source software for healthcare, education, enterprise, development, medical imaging, medical records, and digital pathology.

Visit Medevel

>>> 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?

>Solution :

According to the official docs, ExceptionGroup was only added in Python 3.11. Make sure you check your Python version

Add a comment

Leave a Reply

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use

Discover more from Dev solutions

Subscribe now to keep reading and get access to the full archive.

Continue reading