Overiding error message when using a python program

Simon Brunning simon.brunning at gmail.com
Fri Apr 22 10:56:33 EDT 2005


On 22 Apr 2005 07:45:40 -0700, aleksander.helgaker at gmail.com > I'm
creating this program for my own use but naturally sometimes I
> would make spelling mistakes (being a dyslexic and all) and so having a
> long error message and having the program quit is more then a bit
> irritating. It would be much more preferable if the program simply
> wrote "Command not recognised" and then kept going. Is this possible?

It certainly is. "NameError" is what's called an exception, and you
can catch those. Try something like (untested):

try:
    print 10 / pi
except NameError:
    print "Command not recognised"

I can't see where you'd want that in your code, 'cos I can't see where
you are actually processing the user's input.

For more on exceptions, see <http://docs.python.org/tut/node10.html>.

-- 
Cheers,
Simon B,
simon at brunningonline.net,
http://www.brunningonline.net/simon/blog/



More information about the Python-list mailing list