LearnFrenzy
Sign in Take a free test

Exception Handling · Exercise 1 of 4

Exception Handling Exception Handling MCQ

  • 15 questions
  • Page 2 of 2
  • Answers explained
0Attempted
0Correct
0Wrong
Directions

Fifteen multiple-choice questions on Python exception handling: try, except, else, finally, the hierarchy, raise, custom exceptions, chaining and good practice. Pick an option to check your answer instantly.

Question 11 Medium

Can a try/except in a file catch a syntax error in the same file?

A Yes, with except SyntaxError
B Yes, with a bare except
C No – the file fails to compile before any code runs
D Only if finally is present
Question page & discussion
Question 12 Medium

Why should assert not be used to validate user input?

A assert cannot take a message
B assert raises SyntaxError
C Assertions are removed when Python runs with the -O optimisation flag
D assert only works in functions
Question page & discussion
Question 13 Medium

What does the EAFP coding style mean?

A Check every condition before acting
B Never use exceptions
C Try the operation and handle the exception if it fails
D Catch all exceptions at the top level
Question page & discussion
Question 14 Hard

What happens to the name e after the block except ValueError as e: ends?

A It keeps the exception object
B It becomes None
C It becomes the string message
D It is deleted, so using e afterwards raises NameError
Question page & discussion
Question 15 Easy

What happens with raise "Invalid input"?

A TypeError: exceptions must derive from BaseException
B It raises an Exception with that message
C It prints the message
D SyntaxError
Question page & discussion
Up next · Exercise 2Predict the Output15 questions

Ready to test your Programming?

Timed online tests with instant scores and explanations.

Search LearnFrenzy

Esc

Quick links