Exceptions
Tetsuo
member16943 at dbforums.com
Wed Feb 5 19:35:57 EST 2003
Okay, DBForums and Google show different replies. Praise the Usenet.
I can't figure out what you guys are telling me. I still can't figure
out how to do what I want with Bjorn Pettersen's explanation. All I know
so far is how to raise an exception by creating a program whose only
merit is to raise an exception. Hello World is more useful.
Here's my latest exploit.
class CorruptHardDiskError(Exception):
pass
def Pythagoras(a,b):
if type(a) != type(0) or type(b) != type(0):
raise CorruptHardDiskError
else:
print (a**2 + b**2)**(1/2)
try:
CorruptHardDiskError.Pythagoras(18, "x")
except CorruptHardDiskError:
print "Not a number!"
Oh, this raises an exception alright. But it's the wrong kind. Why? And
what does it mean?
Traceback (most recent call last):
File "D:\Python22\Lib\site-packages\Pythonwin\pywin\framework\scriptu-
tils.py", line 301, in RunScript
exec codeObject in __main__.__dict__
File "D:\Python22\Lib\My stuff\excepttest.py", line 10, in ?
CorruptHardDiskError.Pythagoras(18, "x")
TypeError: unbound method Pythagoras() must be called with
CorruptHardDiskError instance as first argument (got int instance
instead)
--
Posted via http://dbforums.com
More information about the Python-list
mailing list