> > Anything can raise MemoryError. > > Ok. But I don't think regular application code should catch these.
Correct. > > On converting an 8bit string to an int: > > > > ValueError *only* > > Ok. > > > On converting a Unicode string to an int: > > > > ValueError > > UnicodeError (or UnicodeEncodeError, which is a subclass of it) > > Can you provide an example of raising a unicode error like this: > > u = makeUnicodeString() # your choice of function > int(u) In Python 2.3, I get this: >>> int(u"\u1234") Traceback (most recent call last): File "<stdin>", line 1, in ? UnicodeEncodeError: 'decimal' codec can't encode character '\u1234' in position 0: invalid decimal Unicode string >>> In Python 2.2, this raises ValueError. I think I may have to report this as a bug in Python 2.3 though. > My point is that once you have a valid unicode object, I don't see how > calling int(valid_unicode_object) will raise a UnicodeError. > > If this is so, then the style should be: > > value = expression_to_compute_value > try: > i = int(value) > except ValueError: > # take corrective action > > rather than: > > try: > i = int(expression_to_compute_value) > except: # Note: calling 'int()' can raise just about anything > # take corrective action Even if we decide that we have to use a bare except after all, the expression_to_compute_value should still be moved outside the try/except. --Guido van Rossum (home page: http://www.python.org/~guido/) _______________________________________________ Zope-Dev maillist - [EMAIL PROTECTED] http://lists.zope.org/mailman/listinfo/zope-dev ** No cross posts or HTML encoding! ** (Related lists - http://lists.zope.org/mailman/listinfo/zope-announce http://lists.zope.org/mailman/listinfo/zope )