The :keyword:`raise` statement allows the programmer to force a specified
exception to occur. For example::
- >>> raise NameError, 'HiThere'
+ >>> raise NameError('HiThere')
Traceback (most recent call last):
File "<stdin>", line 1, in ?
NameError: HiThere
re-raise the exception::
>>> try:
- ... raise NameError, 'HiThere'
+ ... raise NameError('HiThere')
... except NameError:
... print 'An exception flew by!'
... raise
... print 'My exception occurred, value:', e.value
...
My exception occurred, value: 4
- >>> raise MyError, 'oops!'
+ >>> raise MyError('oops!')
Traceback (most recent call last):
File "<stdin>", line 1, in ?
__main__.MyError: 'oops!'