Exception_handling Flashcards
ValueError
my_int = int(my_string)
If my_string doesn’t hold a string a ValueError arise
TypeError
print (“String#” + 1 + “: “ + my_string) This generate a TypeError because we cannot use the + operator to put together strings and integers
ZeroDivisionError
print (1/0)
This line generates a ZeroDivisionError because we cannot divide by zero
Exception
except Exception as error:
Catch any error
else:
If not errors was encountered then run the code inside this block
finally
The code needs to run regardless of whether an error was detected or not
try block outside the loop
If any iteration of the loop generates an error, it will jump straight down to the except block
A loop inside a try block
If you put a loop inside a try block, then the entire loop terminate when it hits an error
A try block inside a loop
Only the current iteration of the loop will terminate when it hits one error.