]> granicus.if.org Git - python/commitdiff
Define NotANumber as a subclass of ValueError when using class-based
authorFred Drake <fdrake@acm.org>
Tue, 29 Jun 1999 15:49:35 +0000 (15:49 +0000)
committerFred Drake <fdrake@acm.org>
Tue, 29 Jun 1999 15:49:35 +0000 (15:49 +0000)
exceptions.

When raising NotANumber, pass the string that failed as the exception
value.

Lib/fpformat.py

index 8ddd73cf9019ad8f0b91a755e95a5cb2b86aba70..a9c405ee42327395300f025d49745af33350bcf0 100644 (file)
@@ -21,7 +21,11 @@ decoder = re.compile(r'^([-+]?)0*(\d*)((?:\.\d*)?)(([eE][-+]?\d+)?)$')
 # \3 fraction (empty or begins with point)
 # \4 exponent part (empty or begins with 'e' or 'E')
 
-NotANumber = 'fpformat.NotANumber'
+try:
+       class NotANumber(ValueError):
+               pass
+except TypeError:
+       NotANumber = 'fpformat.NotANumber'
 
 # Return (sign, intpart, fraction, expo) or raise an exception:
 # sign is '+' or '-'
@@ -30,7 +34,7 @@ NotANumber = 'fpformat.NotANumber'
 # expo is an integer
 def extract(s):
        res = decoder.match(s)
-       if res is None: raise NotANumber
+       if res is None: raise NotANumber, s
        sign, intpart, fraction, exppart = res.group(1,2,3,4)
        if sign == '+': sign = ''
        if fraction: fraction = fraction[1:]