[Tutor] Trapping High-Level Exceptions As Strings
Tim Johnson
tim at johnsons-web.com
Mon Sep 13 01:41:15 CEST 2004
* Kent Johnson <kent_johnson at skillsoft.com> [040912 11:21]:
<...> If you want to format the traceback differently, you can use some of the
> other functions in the traceback module, for example the various format
> functions. Take a look at traceback.py to see how print_exc() works and
> make your own version that does what you want.
Thanks Kent:
## the code fragment below is what I'm looking for:
etype, value, tb = sys.exc_info()
print "value = " , value
print "tb = " , tb
print "etype = " , etype
print "ERROR LIST = " , traceback.extract_tb(tb)
## shows the following:
value = integer division or modulo by zero
tb = <traceback object at 0x40700c34>
etype = exceptions.ZeroDivisionError
ERROR LIST = [('./nwmls_cron.py', 98, '?', 'process(args)'),
('./nwmls_cron.py', 16, 'process', '1 / 0 # test exception handling and logging')
]
cheers!
tim
<..> At 08:53 AM 9/12/2004 -0800, Tim Johnson wrote:
> >By "High-Level", I mean using the except label
> >without any error object as a parameters, so
> >that I may trap any error that "falls" through
> >more structured traps.
--
Tim Johnson <tim at johnsons-web.com>
http://www.alaska-internet-solutions.com
More information about the Tutor
mailing list