Why exception is not newstyle class?

K

kyo

class A(Exception):

def __init__(self, n):
self.test = n

(1) :

class B(A):

def __init__(self, n):
#A.__init__(self, n)
super(B, self).__init__(n)
self.testb = n

try:
raise B, B(1)
except A, a:
print dir(a)

=============================
(2):

class B(object):
pass
class C(B):
pass
class D(C):
pass


for c in [B, C, D]:
try:
raise c()
except D:
print "D"
except C:
print "C"
except B:
print "B"

================================

I want to use new style class, how to do that?
If I can't, Why?
 
J

Jp Calderone

I want to use new style class, how to do that?
If I can't, Why?

Because Exceptions existed before new-style classes did, and the mechanism
has not yet caught up.

Jp
 

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

No members online now.

Forum statistics

Threads
473,764
Messages
2,569,564
Members
45,040
Latest member
papereejit

Latest Threads

Top