ProgrammingHardWipro · Accenture · Capgemini pattern

What does the following Python 3 code print? class MyErr(Exception): pass try: raise MyErr("custom") except MyErr as e: print("caught", e)

  1. A. MyErr: custom
  2. B. custom
  3. C. caught MyErr
  4. D. caught custom

Correct answer: D. caught custom

A custom exception subclassing Exception behaves like any other; str(e) returns the message passed to the constructor.

More Python Programming questions

Exams that ask this topic