Types of exceptions Flashcards
1
Q
ZeroDivisionError
A
occurs when you try to divide by zero.
2
Q
NameError
A
you tried to use the variable a when it was not defined.
3
Q
IndexError
A
occurs when you try to access data from a list using an index that does not exist for this list.
4
Q
Else
A
else allows one to check if there was no exception when executing the try block. This is useful when we want to execute something only if there were no errors.
5
Q
Finally
A
finally allows us to always execute something even if there is an exception or not. This is usually used to signify the end of the try except.
6
Q
block of code
A
a = 1
try: b = int(input("Please enter a number to divide a")) a = a/b except ZeroDivisionError: print("The number you provided cant divide 1 because it is 0") except ValueError: print("You did not provide a number") except: print("Something went wrong") else: print("success a=",a) finally: print("Processing Complete")