ProgrammingVery hardInfosys HackWithInfy · TCS CodeVita

What is printed?

What is printed?
try:
    try:
        1 / 0
    except ZeroDivisionError:
        raise ValueError('bad')
except ValueError as e:
    print(type(e.__context__).__name__, e)
  1. A. ZeroDivisionError bad
  2. B. ValueError bad
  3. C. ZeroDivisionError division by zero
  4. D. ValueError division by zero

Correct answer: A. ZeroDivisionError bad

When an exception is raised while handling another one, Python stores the first as __context__. The printed message is the ValueError text, and the context is the ZeroDivisionError.

More Python Programming questions

Exams that ask this topic