Next: User-defined Exceptions Up: Errors and Exceptions Previous: Handling Exceptions

Raising Exceptions

The raise statement allows the programmer to force a specified exception to occur. For example:


>>> raise NameError, 'HiThere'
Traceback (innermost last):
  File "<stdin>", line 1
NameError: HiThere
>>>
The first argument to raise names the exception to be raised. The optional second argument specifies the exception's argument.


guido@cwi.nl