Quiz 7: How to work with exceptions

¡Supera tus tareas y exámenes ahora con Quizwiz!

The finally clause of a try statement

is executed whether or not an exception has been thrown

If a program attempts to read from a file that does not exist, which of the following will catch that error?

FileNotFoundError and OSError

Which of the following is the correct way to code a try statement that catches any type of exception that can occur in the try clause?

NOT try: number = float(input("Enter a number: ")) print("Your number is: ", number) except ValueError: print("Invalid number.")

Within the try clause of a try statement, you code

a block of statements that might cause an exception

A Python program should use try statements to handle

all exceptions that can't be prevented by normal coding techniques

It's a common practice to throw your own exceptions to test error handling routines that

catch exceptions that are hard to produce otherwise

To cancel the execution of a program in the catch clause of a try statement, you can use the

exit() function of the sys module

To throw an exception with Python code, you use the

raise statement

When an exception is thrown, Python creates an exception object that contains all but one of the following items of information. Which one is it?

the severity of the exception

Which of the following is the correct way to code a try statement that displays the type and message of the exception that's caught?

try: number = int(input("Enter a number: ")) print("Your number is: ", number) except Exception as e: print(type(e), e)


Conjuntos de estudio relacionados

Data Analysis: Chapter 11: Analysis of Variance

View Set

2B La casa /placement phrases, Irregular Preterite Conjugations QUIZ PRACTICE

View Set

AP Computer Science Practice Exam A

View Set

Tenses: Present Simple and Present Continuous

View Set

Chapter 1 Regulation of Securities Markets

View Set