handling errors

Peter Hansen peter at engcorp.com
Thu Jun 5 03:58:43 CEST 2003


ataraxia2500 wrote:
> 
> I got that little piece of code on a tutorial. I want to add an error
> handling to the print_menu function so that if the user enter strings
> instead of int the program doesn't crash but I couldn't make it. I tried to
> add: "except ValueError:
>         print "That was not a number.""
> at the end but it didn't do anything. any idea how I should use it?

Please post your trial using "try/except" so we can see what you were
doing wrong.  (You probably can omit most of the middle stuff, where
you test menu_choice with the if/elifs, to cut down the length of the
posting, if you wish.)

-Peter




More information about the Python-list mailing list