confusion around CustomException example in 'Python in a Nutshell'

Peter Hansen peter at engcorp.com
Sun Mar 13 10:57:19 EST 2005


erick_bodine at comcast.net wrote:
> <classic keyboard fumbling>  What I am trying to do is get information
> from a raised custom exception.  I am catching the exception in a
> main() function but it was actually raised in a separate module
> function.  It would be nice if I could print out where the exception
> was raised from (module.function name + line number).

Ah, good.  Exactly what the useful functions in the
'traceback' module are intended for, if I understand
your meaning...

If doing "traceback.print_exc()" is printing the
information you want (in a traceback that has much
more than what you say you want), then you can use
the other functions in that module, and methods in
the 'traceback' objects themselves (the third item
in the tuple returned by sys.exc_info()), will
give you all you could ever want...

Google can help you find examples of usage as well,
in the archives for this group.

-Peter



More information about the Python-list mailing list