A Catch-all Exception-Handler

Fredrik Lundh fredrik at pythonware.com
Fri May 7 06:48:21 EDT 1999


Norbert Klamann wrote:
> since some weeks I do serious work with Python and I like it very much.
> I wrote some scripts which run nightly in batch . At the moment I don't
> see a possibility to make any unforeseen exceptions visible.
> 
> The scripts print to stdout and in case of an exceptional exception I would
> like to see a traceback on Stdout.
> 
> If possible I wouldn't like to clutter the code with try's and except's at
> every second line.

import traceback, sys

for stuff in things_to_do():
    try:
        do(stuff)
        print stuff, "ok"
    except:
        print stuff, "FAILED"
        traceback.print_exc(file=sys.stdout)

</F>





More information about the Python-list mailing list