Re: Python less error-prone than Java



Simon Percivall <percivall@xxxxxxxxx> wrote:
...
with static typing. The equivalent in Python would have been if an
overflow exception was raised when the int got too big. It might have
been that way, typing or no typing.

Indeed, it _used_ to be that way --
<http://docs.python.org/lib/module-exceptions.html> STILL says...:

exception OverflowError

Raised when the result of an arithmetic operation is too large to be
represented. This cannot occur for long integers (which would rather
raise MemoryError than give up). Because of the lack of standardization
of floating point exception handling in C, most floating point
operations also aren't checked. For plain integers, all operations that
can overflow are checked except left shift, where typical applications
prefer to drop bits than raise an exception.


Actually, the docs are obsolete on this point, and an int becomes a long
when that's necessary:

sys.maxint+1
2147483648L

but, this operation _would_ have raised OverflowError in old-enough
versions of Python (not sure exactly when the switch happened...).


Alex
.



Relevant Pages

  • Re: interrupting for overflow and loop termination
    ... > only this int can ever overflow. ... maybe all you need is a sticky overflow bit. ... When a user-level instruction X caused an exception, ... The CAUSE register was set to indicate the reason. ...
    (comp.arch)
  • Re: math.nroot [was Re: A brief question.]
    ... >>> wish sometimes that Python would make up it's mind about what it does ... >> exception on overflow, invalid operation, and divide by 0, and "should ... >> not", by default, raise an exception on underflow or inexact. ... you can at least be pretty sure that an infinite result is the ...
    (comp.lang.python)
  • Re: GEOMETRIC mean computation: TEST of proposed tecniques for
    ... possibility of Overflow or Underflow when multiplying ... In fact if your language allows exception handling you may write code ... Raymond- Nascondi testo tra virgolette - ... Instead of checking that the mean is greater that an upport threshold ...
    (sci.math)
  • Re: floating point over-/under-flow
    ... > I'm interested to hear the c.l.c set of viewpoints on silent vs. noisy ... > ('Very-noisy' would be throwing an exception of some kind, ... > hitting overflow and underflow? ... Long, long ago, before C, the usual practice for such hardware was to throw ...
    (comp.lang.c)
  • Re: Error occurring in error handler
    ... "Run-time error '6'" Overflow is an error which is trapped bya processor ... exception, then passed back up to your error handler.It doesn't have to come ...
    (comp.databases.ms-access)

Loading