Entry
Printing exception traceback to stdout
Jul 5th, 2000 10:03
Nathan Wallace, Hans Nowak, Snippet 354, Fredrik Lundh
"""
Packages: exceptions
"""
"""
> 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)