Why don't other programming languages have ranges?

Jim Balter Jim at Balter.name
Mon Jul 26 21:11:12 PDT 2010


"bearophile" <bearophileHUGS at lycos.com> wrote in message 
news:i2knnc$1ftr$1 at digitalmars.com...
> Walter Bright:
>> 1. segfaults *are* exceptions.
>
> Aren't exceptions objects?
>
> Bye,
> bearophile

Not at all -- exceptions are system-generated events that are implemented in 
modern languages by the equivalent of a throw statement, and Exception 
objects are used to communicate information about either system- or user- 
generated throws. And Walter's point is getting lost -- 'retard' 
misidentified the issue as giving up speed by going with "exceptions" to 
avoid "hard crashes" such as segfaults, but of course there is no loss of 
speed for catching a segfault signal -- an asynchronous event -- and 
throwing an Exception object rather than calling a C signal catcher. The 
speed cost doesn't come from using Exceptions, it comes from doing array 
bounds checking (which, of course, results in an Exception object being 
thrown if violated). Of course, in D, if you're desperate for it, you can 
regain the speed by giving up the memory safety and using pointers, in which 
case an array bounds violation might overwrite something -- and if the thing 
overwritten is a pointer, that is likely to result in a segfault -- which is 
an exception, which in D will cause an Exception object to be thrown. Of 
course, in languages that have them, objects are used to communicate the 
information about exceptions, but even in C there are (non standard) 
libraries available that provide a catch/throw/exception-passing mechanism 
using a stack of setjmp structs and a longjmp for the throw. 



More information about the Digitalmars-d mailing list