Exception not captured

M

Miki Tebeka

Hello All,

Can someone please explain how is the following code fragment possible?
(If you're interested I can place the whole project somewhere).

def checkout(dest, log):
'''Get latest version from SCM

client - SCM client to use
dest - Destination directory
'''
try:
SCM.checkout(dest, log)
except SCMError, e:
raise NightlyError("Checkout")
except Exception, e:
import inspect
file = inspect.getsourcefile(e.__class__)
line = inspect.getsourcelines(e.__class__)[1]
print "%s:%d" % (file, line)
file = inspect.getsourcefile(SCMError)
line = inspect.getsourcelines(SCMError)[1]
print "%s:%d" % (file, line)
print SCMError is e.__class__
raise SystemExit

I get to the second "except" clause, and the printout is:
/home/mikit/work/nightly/scm/common.py:3
/home/mikit/work/nightly/scm/common.py:3
False

How is this possible?
Bye.
 
P

Peter Otten

Miki said:
Hello All,

Can someone please explain how is the following code fragment possible?
(If you're interested I can place the whole project somewhere).

def checkout(dest, log):
'''Get latest version from SCM

client - SCM client to use
dest - Destination directory
'''
try:
SCM.checkout(dest, log)
except SCMError, e:
raise NightlyError("Checkout")
except Exception, e:
import inspect
file = inspect.getsourcefile(e.__class__)
line = inspect.getsourcelines(e.__class__)[1]
print "%s:%d" % (file, line)
file = inspect.getsourcefile(SCMError)
line = inspect.getsourcelines(SCMError)[1]
print "%s:%d" % (file, line)
print SCMError is e.__class__
raise SystemExit

I get to the second "except" clause, and the printout is:
/home/mikit/work/nightly/scm/common.py:3
/home/mikit/work/nightly/scm/common.py:3
False

How is this possible?

Some kind of duplicate import, maybe? E.g.:
import sys
import inspect
getsource = inspect.getsource
del sys.modules["inspect"]
import inspect
getsource is inspect.getsource
False

Peter
 
R

Roy Smith

Miki Tebeka said:
print SCMError is e.__class__
raise SystemExit

I get to the second "except" clause, and the printout is:
/home/mikit/work/nightly/scm/common.py:3
/home/mikit/work/nightly/scm/common.py:3
False

How is this possible?

I suspect you meant to do:

print "SCMError is", e.__class__

The way you have it now, it's printing out the result of the "is"
operator, which tests for identity.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
473,769
Messages
2,569,579
Members
45,053
Latest member
BrodieSola

Latest Threads

Top