raise() python code example
Example 1: raise python
raise(Exception("Put whatever you want here!"))
raise(TypeError)
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
Example 3: python: raise error
class MyError(TypeError):
pass
raise MyError('An error happened')