except ValueError, e: What needs to be changed to run in Python 3? code example
Example 1: error handling Pyhtin
try:
age = int(input("Please enter your age: "))
print(age)
except:
print("please enter a number instead! ")
print('bye')
while True:
try:
age = int(input("Please enter your age: "))
print(age)
except:
print("please enter a number instead! ")
else:
break
Example 2: exception variable properties python
>>> try:
... raise Exception('spam', 'eggs')
... except Exception as inst:
... print(type(inst))
... print(inst.args)
... print(inst)
...
... x, y = inst.args
... print('x =', x)
... print('y =', y)
...
<class 'Exception'>
('spam', 'eggs')
('spam', 'eggs')
x = spam
y = eggs