diff options
author | Fred Drake <fdrake@acm.org> | 1999-06-29 15:49:35 (GMT) |
---|---|---|
committer | Fred Drake <fdrake@acm.org> | 1999-06-29 15:49:35 (GMT) |
commit | b8690fbc951fd937b2c3306da374e0f2d45088a6 (patch) | |
tree | 247ac700e8d0103a36e808017b60e31275f6b388 /Lib/fpformat.py | |
parent | 9e0b6229f64fed74720f86a1d774824f20d46f24 (diff) | |
download | cpython-b8690fbc951fd937b2c3306da374e0f2d45088a6.zip cpython-b8690fbc951fd937b2c3306da374e0f2d45088a6.tar.gz cpython-b8690fbc951fd937b2c3306da374e0f2d45088a6.tar.bz2 |
Define NotANumber as a subclass of ValueError when using class-based
exceptions.
When raising NotANumber, pass the string that failed as the exception
value.
Diffstat (limited to 'Lib/fpformat.py')
-rw-r--r-- | Lib/fpformat.py | 8 |
1 files changed, 6 insertions, 2 deletions
diff --git a/Lib/fpformat.py b/Lib/fpformat.py index 8ddd73c..a9c405e 100644 --- a/Lib/fpformat.py +++ b/Lib/fpformat.py @@ -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:] |