#-----------------------------
from mylibrary import *
x = 7 / 0
#-----------------------------
such that I can control what happens when an unhandled exception is
thrown. I want to put something in mylibrary. Now, I know I can:
#-----------------------------
import sys
try:
x = 7 / 0
except:
custom_handler(sys.exc_type, sys.exc_value, sys.exc_traceback)
#-----------------------------
but I don't want to surround all of my code in a try/except clause. Is
this possible? Are there hooks into the standard interpreter's
unhandled exception handling?
Thanks for any hints,
-Doug
http://docs.python.org/lib/module-traceback.html
Cheers,
Vern
--
This time for sure!
-Bullwinkle J. Moose
-----------------------------
Vern Ceder, Director of Technology
Canterbury School, 3210 Smith Road, Ft Wayne, IN 46804
vce...@canterburyschool.org; 260-436-0746; FAX: 260-436-5137
You can take a look at sys.excepthook and see if that does what you
need.
For example:
>>> import sys
>>> def myhook(type, value, traceback):
... print 'type:', type
... print 'value:', value
... print 'traceback:', traceback
...
>>> sys.excepthook = myhook
>>> 1/0
type: <type 'exceptions.ZeroDivisionError'>
value: integer division or modulo by zero
traceback: <traceback object at 0x63fd0>
I hope that helps.
--Dethe
On 4-Oct-06, at 10:06 AM, Doug wrote:
>
> I'm interested in exploring a custom traceback error handler, but I
> can't figure out if it is possible. I'd like to do something like:
>
> #-----------------------------
> from mylibrary import *
> x = 7 / 0
> #-----------------------------
>
> such that I can control what happens when an unhandled exception is
> thrown. I want to put something in mylibrary. Now, I know I can:
>
> #-----------------------------
> import sys
> try:
> x = 7 / 0
> except:
> custom_handler(sys.exc_type , sys.exc_value, sys.exc_traceback)
> #-----------------------------
>
> but I don't want to surround all of my code in a try/except clause. Is
> this possible? Are there hooks into the standard interpreter's
> unhandled exception handling?
>
> Thanks for any hints,
>
> -Doug
>
>
>
in the Internet Age. --Dean Baker
The deadline for submissions of presentation proposals for PyCon 2007 is October 31st. Given how much good came out of getting education meetings at last year's pycon (this list, for starters), I wanted to see if we could do some advanced planning to make this year's pycon even better.
I've got to run (students are coming), so I'll follow this up later...
jeff elkner
Do we want to suggest an education strand? Well, maybe not quite a
strand, but at least some grouping of ed related talks?
Cheers,
Vern
--