[Tutor] Error handling in functions / main program
Lloyd Kvam
pythonTutor at venix.com
Thu Aug 12 17:34:29 CEST 2004
This is tough to answer and depends a lot on the context. Different
folks are likely to give different responses.
My rules of thumb:
User input NEVER causes a program failure. try/except catches ALL
errors and provides a (hopefully) useful error message and a chance to
provide valid input.
If the program fails in an unexpected area, report the failure and
exit. This is likely to be a blanket try/except in main. It does NOT
try to keep the program running, but simply provides a graceful
shutdown. I like to email program traces back to me so that I can
quickly respond to problems.
I think that each try/except should be carefully programmed to deal with
EXPECTED errors. A try/except that covers too much will likely do the
wrong thing when presented with the unexpected error. My programs
usually have only a handful of try/except statements usually related to
user-input errors, network errors, and those fairly rare cases where
processing errors are expected and there is a reasonable recovery
strategy.
On Thu, 2004-08-12 at 11:09, Klas Marteleur wrote:
> ...and i am also planing to write a little GUI in another file
> -----------------------------------------------------------
> Now to my questions:
> How much and what type of error handling should be handled by:
> 1. The functions
> 2 The main program / GUI program.
>
> I mean i could add a lot of extra error checking in the functions (... so that
> correct inputs are used etc)? Or should that be the responsebility of the
> main program to asure that the input to the functions are correct?
> Then what type of error handling should be located in the functions?
> -----------------------------------------------------------
>
> I hope my questions wasnt to confusing (english is not my native language).
>
> Kind regards
> Klas
> _______________________________________________
> Tutor maillist - Tutor at python.org
> http://mail.python.org/mailman/listinfo/tutor
--
Lloyd Kvam
Venix Corp.
1 Court Street, Suite 378
Lebanon, NH 03766-1358
voice: 603-653-8139
fax: 801-459-9582
More information about the Tutor
mailing list