All quizzesEasy
Try, Except & Finally — Series 2
Preview — 3 of 10 questions
What is the output of the following code?
javascript
class ConfigError(Exception):
pass
try:
raise ConfigError("missing config file")
except ConfigError as e:
print(str(e))
print(e.args)Amissing config file, ('missing config file',)
BConfigError('missing config file'), ('missing config file',)
Cmissing config file, [] — a subclass with no __init__ override never populates .args.
DTypeError: ConfigError() missing 1 required positional argument
What is the output of the following code?
javascript
try:
try:
1 / 0
except TypeError:
print("inner caught TypeError")
except ZeroDivisionError:
print("outer caught ZeroDivisionError")Ainner caught TypeError
Bouter caught ZeroDivisionError
CBoth are printed.
DNothing is printed; the ZeroDivisionError propagates uncaught.
What is the output of the following code?
javascript
try:
raise "just a string"
except TypeError as e:
print("TypeError:", e)Ajust a string
BSyntaxError: cannot raise a string literal
CTypeError: exceptions must derive from BaseException
DThe string is silently ignored, and execution continues normally past the try block.
Sign up free to play
Answer all 10 questions (7 more), see explanations for every answer, and track your score.