python print exception error code example
Example 1: how to print error in try except python
try:
except Exception as e:
print("ERROR : "+str(e))
Example 2: exception pyton print
except Exception as e: print(e)
Example 3: raise python
raise(Exception("Put whatever you want here!"))
raise(TypeError)
Example 4: 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 5: only try python
try:
a=2
except:
pass