question about sys.exc_type and sys.exc_value

John Salerno johnjsal at NOSPAMgmail.com
Sat Mar 4 20:18:27 EST 2006


Here is an exercise from Learning Python that I wrote myself:

import sys
import traceback

class MyError: pass

def oops():
     raise MyError()

def safe(func, *args):
     try:
         apply(func, args)
     except:
         traceback.print_exc()
         print 'Got', sys.exc_type, sys.exc_value

safe(oops)

And here is the output:

Traceback (most recent call last):
   File "C:/Python24/oops.py", line 11, in safe
     apply(func, args)
   File "C:/Python24/oops.py", line 7, in oops
     raise MyError()
MyError: <__main__.MyError instance at 0x00B475A8>
Got Queue.Empty

Why does it show Queue.Empty as the values for sys.exc_type and 
sys.exc_value? I guess I can somewhat understand Empty, because the 
instance is basically nothing. But why does it say Queue instead of 
MyError? The sample in the book shows "Got hello world", because hello 
is the error name and world is the extra data. But mine doesn't seem to 
work that way. (They are also using a string exception in the book, 
instead of a class.)

Thanks.



More information about the Python-list mailing list