python print exception in except code example
Example 1: how to print error in try except python
try:
except Exception as e:
print("ERROR : "+str(e))
Example 2: python except print error type
>>> 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
Example 3: python try except: print error
except Exception as e: