ProgrammingVery hardGATE CS · Product-company placement

What is printed?

What is printed?
try:
    raise ExceptionGroup("g", [ValueError(1), TypeError(2), ValueError(3)])
except* ValueError as eg:
    print(len(eg.exceptions), end=" ")
except* TypeError as eg:
    print(type(eg).__name__, end=" ")
  1. A. 1 TypeError
  2. B. 2 TypeError
  3. C. 2 ExceptionGroup
  4. D. 3 ExceptionGroup

Correct answer: C. 2 ExceptionGroup

except* splits the group: the ValueError handler gets a sub-group with both ValueErrors, and the TypeError handler also runs, receiving an ExceptionGroup wrapping the TypeError. More than one except* clause can run.

More Python Programming questions

Exams that ask this topic