class RangeException(Exception) :
def __init__(self, low, high) :
self.low = low
self.high = high
def __str__(self) :
s = "Expected value in range "+str(self.low)
s = s + " to "
s = s + str(self.high)
return s
def CheckValue( inV ) :
if ( inV < 0 or inV > 10 ) :
raise RangeException(0,10)
return True
CheckValue(12)
import sys
try :
CheckValue(12)
except Exception:
print sys.exc_info()
try :
CheckValue(12)
except RangeException, re:
print "You didn't enter a value between: "+str(re.low)+", and "+str(re.high)
|