how to identify error type in a try except python 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: only try python
try:
a=2
except:
pass