Types of exceptions Flashcards

You may prefer our related Brainscape-certified flashcards:
1
Q

ZeroDivisionError

A

occurs when you try to divide by zero.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
2
Q

NameError

A

you tried to use the variable a when it was not defined.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
3
Q

IndexError

A

occurs when you try to access data from a list using an index that does not exist for this list.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
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.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
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.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
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")
How well did you know this?
1
Not at all
2
3
4
5
Perfectly