[Tutor] Error handling in functions / main program

Alan Gauld alan.gauld at blueyonder.co.uk
Thu Aug 12 22:58:16 CEST 2004


> There was a good example of this on the list recently where the main
> program had a try/except that just printed an error and exited.

As author of that program I'd better point out that I agree.
When testing and debugging avoid catch-all excepts at the top
level. Only put that in once you are confident it works and
use it to shelter the user from unfriendly error messages.

> The logging module can help with this - you can put detailed error
messages
> in a log file and simple messages in the UI.

This too is good advice, even with the catchall except you should
log the error and display a friendly message to the user - best
of both worlds. In my defence the logging module didn't exist
when I wrote the book and dealing with the traceback manually was
too advanced for my audience... :-)

Alan G
Author of the Learn to Program web tutor
http://www.freenetpages.co.uk/hp/alan.gauld/tutor2/



More information about the Tutor mailing list