I want to keep & use the error value of an exception in both Python 2.5, 2.7 and 3.2.
In Python 2.5 and 2.7 (but not 3.x), this works:
try:
print(10 * (1/0))
except ZeroDivisionError, error: # old skool
print("Yep, error caught:", error)
In Python 2.7 and 3.2 (but not in 2.5), this works:
try:
print(10 * (1/0))
except (ZeroDivisionError) as error: # 'as' is needed by Python 3
print("Yep, error caught:", error)
Is there any code for this purpose that works in both 2.5, 2.7 and 3.2?
Thanks