My code is below. The exception handling itself works, but I am unable to get the error messages specified to print.
import numpy as np
def compute_circle_area(r):
try:
if type(r) == 'complex' :
raise(TypeError('Argument is complex'))
elif r < 0 :
raise(ValueError('Argument < 0'))
elif type(r) == str :
raise(TypeError('Argument is wrong type'))
a = np.pi * r * r
except ValueError as ve:
print("Value Error", ve)
except TypeError as te:
print("Type Error", te)
else:
print('Argument works, solution is: ', a)
finally:
print("Let's continue")
print(compute_circle_area(2.1))
print(compute_circle_area(2+1j))
print(compute_circle_area(-2.1))
print(compute_circle_area('radius'))