From: fredrik at pythonware.com (Fredrik Lundh)
Date: Fri, 7 May 1999 10:48:21 GMT
Subject: A Catch-all Exception-Handler
References: <7gu39c$i63$1@nnrp1.deja.com>
Message-ID: <009001be987b$a46081a0$f29b12c2@pythonware.com>
X-UID: 1910                                                 

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>





