Now that you can catch errors and turn them into simple exceptions. The question begs asking: "How do you catch more than one kind of error?" Simple: Use multiple except statements.
If, for example, we take Hetland's example of dividing by 0 and turn the division equation into variables instead of values, we should check for both attribution of value and zero division. In which case, we want a program like that below.
a = input("Please enter the dividend (the number to be divided):")
b = input("Please enter the divisor (the number by which to divide):")
try:
print a/b
except NameError:
print "Both values must be integers!"
except ZeroDivisionError:
print "The divisor must not be zero. Division by null is not allowed."
Similarly, if you need to do more calculations with the two values (e.g., monetary conversion for multiple currencies), you can lob all of the calculations into the single try statement. If anything goes wrong, the same except statements for one calculation will pick up the mathematical debris of the others.
If you would like to perform the same action on multiple errors, you can combine the errors into a single argument for except:
a = input("Please enter the dividend (the number to be divided):")
b = input("Please enter the divisor (the number by which to divide):")
try:
print a/b
except (NameError, ZeroDivisionError):
print "The divisor must not be zero. Null division is not allowed."
