Python 101 (part 8): An Exceptionally Clever Snake (
Page 1 of 9 )
In this concluding article of the Python 101 series, find out how
to use Python's exception-handling routines to trap and resolve program
errors, learn to generate and use custom error messages, and get acquainted
a bunch of useful (and free!) Python resources online.If you've been following along since the beginning, I think you'll agree
with me that it's certainly been an interesting eight weeks.
Together, we've visited all the standard attractions - we've thumbed
through the rulebook for strings, numbers, lists, dictionaries and those
oddly-named tuples; mucked around with system files and directories;
packaged code into functions and functions into modules; and dissected the
Python interpreter and some of Python's innumerable built-in functions -
and indulged in some decidedly non-standard activities - learning the names
of exotic Italian dishes; stomping on all kinds of creepy-crawlies;
attempting to con unwitting customers into purchasing air in a bottle; and
hooking up with old flames, new superheroes and the complete cast of "Star
Wars".
In this concluding article, I'm going to be demonstrating Python's
error-handling routines, and showing you how to wrap your code in them to
avoid violent - and potentially embarrassing - flame-outs. I'll be
explaining the different types of errors you might encounter and the Python
constructs available to manage them, with examples that demonstrate just
how powerful this capability really is.
Talk about getting your money's worth!