ProgrammingHardGATE CS · Product-company placement

What is printed?

What is printed?
class AppError(Exception): pass
class DBError(AppError): pass
try:
    raise DBError("db")
except Exception:
    print("Exception", end=" ")
except AppError:
    print("AppError", end=" ")
print(issubclass(DBError, Exception), isinstance(DBError(), AppError))
  1. A. AppError True True
  2. B. Exception True True
  3. C. Exception AppError True True
  4. D. AppError False True

Correct answer: B. Exception True True

except clauses are tested top to bottom and the first match wins; Exception matches every subclass, so the more specific AppError handler is unreachable.

More Python Programming questions

Exams that ask this topic