[Tutor] exceptions
dman
dman@dman.ddts.net
Mon, 15 Apr 2002 20:16:29 -0500
On Mon, Apr 15, 2002 at 10:22:58AM +0100, alan.gauld@bt.com wrote:
| > How do you approach error trapping and use exceptions in Python to
| > take care of it? How do you for all the possible dumb user mistakes?
|
| My tutor contains a page on this subject, plus we just had a thread on it.
|
| > I mean give me the kind of thought process of how I should go about
| > thinking this through in planning my program.
To echo Sean and Alan, I start out accepting only good input. As I
see where I mess up I add rudimentary error handling and build it up
as I consider everything that can go wrong. Often times it is just a
matter of seeing the list of exceptions a library method can raise and
doesn't necessarily require a full understanding of every possible
situation that can cause the method to fail.
| For production code I routinely put a try:/except/
| handler around my entire program which just says
| "Oops something unexpected happened". But thats just
| to shield the gentle users from unsightly stack traces.
| I comment it out during development/testing.
I do the same thing, if the code is going to be production. (that is,
if it will be more than a script that only I will use) That is
especially important for a daemon that has no stdout for python to
dump a stack trace to. Instead I must catch the exception and record
the error in the syslog so it can be tracked down later.
-D
--
A)bort, R)etry, D)o it right this time