Exception_handling Flashcards

1
Q

ValueError

A

my_int = int(my_string)

If my_string doesn’t hold a string a ValueError arise

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

TypeError

A

print (“String#” + 1 + “: “ + my_string) This generate a TypeError because we cannot use the + operator to put together strings and integers

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

ZeroDivisionError

A

print (1/0)
This line generates a ZeroDivisionError because we cannot divide by zero

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

Exception

A

except Exception as error:

Catch any error

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

else:

A

If not errors was encountered then run the code inside this block

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

finally

A

The code needs to run regardless of whether an error was detected or not

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

try block outside the loop

A

If any iteration of the loop generates an error, it will jump straight down to the except block

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

A loop inside a try block

A

If you put a loop inside a try block, then the entire loop terminate when it hits an error

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

A try block inside a loop

A

Only the current iteration of the loop will terminate when it hits one error.

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