But what if you do not want to give the user something obtuse like NameError or IOError. Python also provides a way to present customised error messages by using the built-in class Exception. To use it, simply plug "Exception" as the argument of raise.
>>> raise Exception"Where is the error message?" Well, I wanted you to see that you could raise a simple error by not giving any further arguments than "Exception". If you want to print something beyond this, enclose your message in quotes and separate it from "Exception" by a comma:
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
Exception
>>> raise Exception, "This is my customised error message."
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
Exception: This is my customised error message.
That summarises Python's exceptions, if you would like a list of them, you will find a page each of Python's exceptions and warnings in the section on the Python Library.
Other tutorials in this series: 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8

