def sum(nums):"""Try to catch all of our exceptions only.Re-raise them with more specific details."""result = 0
try:iter(nums)except TypeError as e:raise TypeError("nums must be iterable")
for n in nums:try:result += int(n)except TypeError as e:raise TypeError("stopped mid iteration since a non-integer was found")
return result