python has man differnt error messges
errors are sometimes called exceptions
https://docs.python.org/3/library/exceptions.html#exception-hierarchy
https://www.w3schools.com/python/python_ref_exceptions.asp
TypeError: using the wrong data type
ValueError: a value is not in the acceptable range
a traceback is an error report that helps fixing the code
a traceback can go back into the package's source code
raise gives a specific error message
produces an error message, and code will stop
def my_function(attribute):
if type(attribute) == str:
print(attribute)
else:
raise TypeError("My error message.") #an error will appear as 'TypeError: My error message.'
try checks for errors inside a function
except gives out the error message
produces an error message, but subseqent code will run
def my_function(attribute):
try:
output = sum(attribute) / len(attribute)
return output
except:
print("My error message.")
try:
result = entry * 1.5
except:
raise My_Exception("my description")
else:
print(result)
finally:
print("my suggestion")
try:
result = var_1 / var_2
except:
pass
else:
print(result)