comp.lang.ada
 help / color / mirror / Atom feed
From: Robert A Duff <bobduff@shell01.TheWorld.com>
Subject: Re: Ada exception block does NOT work?
Date: 18 Aug 2005 16:56:35 -0400
Date: 2005-08-18T16:56:35-04:00	[thread overview]
Message-ID: <wcc3bp7klq4.fsf@shell01.TheWorld.com> (raw)
In-Reply-To: de1hpr$4s$1@sunnews.cern.ch

Maciej Sobczak <no.spam@no.spam.com> writes:

> Jeffrey R. Carter wrote:
> 
> > Ada has had exceptions, well integrated with the rest of the language,
> > since Ada 80. Ada's terminology is that exceptions are raised and
> > handled.
> 
> OK, but the question is not about terminology, really.

It is unfortunate that different programming languages use different
terminology for what is essentially the same concept.  "Raise" and
"handle" mean essentially the same thing as "throw" and "catch".
There are important differences in syntax and semantics among different
languages, but terminology differences just get in the way of
understanding the "real" differences.  And the differences between C++
and Java are just as important as the differences between C++ and Ada,
even though C++ and Java use more-similar terminology.

Anyway, if you say "throw" in an Ada newsgroup, folks ought to know what
you're talking about.

> If you claim that exceptions were "patched" on to the C++ language that
> did not have them originally, then let's switch the context to other
> language that has no history issue like this.
> 
> I don't know the full history of Java, but I suppose that it had
> exceptions from the very beginning.

Yes, it did.

>... If not, let's take C#. Whether those
> languages tried to mimic the syntax from C++ does not matter at all when
> it comes to discussion how well the mechanism is integrated into the
> language.

Agreed.

> Why do you claim that Ada's exceptions are "better integrated into the
> language than in the languages that throw and catch them"?

Well, given something that ought to be considered an "error", the
language designer has to decide how to deal with it: make it raise/throw
an exception, or make it return a well-defined but likely-wrong answer,
or make the behavior "unpredictable", or restrict things so it can be
detected at compile time, or ....

The raise/throw exception choice was not available to Stroustrup when he
designed C++, since C++ at that time had no exception facility, and
since he intended to be compatible with C.  This has nothing to do with
whether you call it "raise" or "throw".  But it does mean that
exceptions are not well-integrated, since certain run-time errors that
really ought to cause exceptions do not.  For example, overflow on
signed integer arithmetic.  On this point, I agree with Jeff Carter.

On the other hand, the Java designers were not trying to be compatible
with C, and could well have made signed integer overflow throw an
exception.  But they chose instead to make it return a probably-wrong
answer; that is, they unwisely chose wraparound arithmetic.

On the third hand, *unsigned* integer arithmetic is wrap-around in C,
C++, Java, *and* Ada.

----------------

As to the syntax: I think the try/catch statement or whatever is
*better* than the Ada syntax, because it makes it quite clear which
region of code is protected by the handler.  In Ada:

    procedure P(...) is
        ... -- (1)
    begin
        ... -- (2)
    exception
        when Some_Error =>
            Do_Something;
    end P;

An exception at (2) is handled by the handler, whereas an exception at
(1) is not.  But it *looks* like both should be handled, from the
syntax, and the usual indentation.  More importantly, one moves code
above/below the "begin" line based on criteria having nothing to do with
exceptions -- whether it's needed to initialize or constrain things, for
example.

There are, of course, good reasons why exceptions at (1) are not handled
by the above handler.  But I think the try/catch syntax deals with these
issues more neatly.

> Note that those other languages can throw regular objects as exceptions,
> thus enabling polymorphism when they are handled. One could say that
> *this* is the point of good integration and that Ada's exceptions are a
> conceptual patch that did not integrate with the rest of the object
> model, leading to two separate spaces of language entities instead of
> only one.

I agree.  If you want to attach information to an exception in Java, you
do it in the same way you attach information to any other sort of object
-- you declare record fields in a type extension (i.e. in a class in the
exception hierarchy).  In Ada, you have to use a special gizmo.  The
Java way is clearly more well-integrated with the rest of the language.

Besides, the Java way is type safe at compile time, whereas the Ada
gizmo is not.

On the other hand, in C++, an exception can be *anything* -- you can
throw a string, or an int.  I don't like that.

> Note that I'm learning Ada and I'm likely to misunderstand things.

Perhaps, but you seem to understand the exception-related issues just
fine.  ;-)

>... But
> I'm curious about your way of reasoning and I want to better understand
> the differences between languages (and that's why I'm provoking you with
> the above inverted claim ;) ).

- Bob



  parent reply	other threads:[~2005-08-18 20:56 UTC|newest]

Thread overview: 78+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2005-08-16  8:48 Ada exception block does NOT work? bubble
2005-08-16  9:00 ` Georg Bauhaus
2005-08-16  9:32   ` bubble
2005-08-16  9:42     ` gautier_niouzes
2005-08-16 15:25       ` Frank J. Lhota
2005-08-16 16:58         ` Svesse
2005-08-16 17:48           ` Björn Persson
2005-08-16 18:12             ` Svesse
2005-08-16 18:17           ` Frank J. Lhota
2005-08-17 10:53         ` Ludovic Brenta
2005-08-17 11:34           ` Anders Wirzenius
2005-08-17 18:08             ` Björn Persson
2005-08-17 19:05               ` Randy Brukardt
2005-08-18 15:58               ` Georg Bauhaus
2005-08-16 12:30     ` Georg Bauhaus
2005-08-16 17:39       ` Björn Persson
2005-08-16 19:43         ` Georg Bauhaus
2005-08-17  1:39     ` Jeffrey R. Carter
2005-08-17  7:22       ` Maciej Sobczak
2005-08-18  1:05         ` Jeffrey R. Carter
2005-08-18  8:44           ` Maciej Sobczak
2005-08-18 11:40             ` Jean-Pierre Rosen
2005-08-18 12:56               ` Maciej Sobczak
2005-08-18 14:42                 ` Jean-Pierre Rosen
2005-08-18 18:03                 ` Martin Krischik
2005-08-18 13:15               ` Alex R. Mosteo
2005-08-18 15:23                 ` Dmitry A. Kazakov
2005-08-18 18:00                 ` Martin Krischik
2005-08-18 16:13             ` Jeffrey Carter
2005-08-18 16:38               ` Hyman Rosen
2005-08-18 18:07                 ` jimmaureenrogers
2005-08-18 18:44                   ` Hyman Rosen
2005-08-18 20:52                     ` Frank J. Lhota
2005-08-19  0:57                     ` jimmaureenrogers
2005-08-19  7:52                       ` Dmitry A. Kazakov
2005-08-19 14:41                       ` Robert A Duff
2005-08-19 17:48                   ` Martin Krischik
2005-08-19 14:58                 ` Robert A Duff
2005-08-18 17:54             ` Martin Krischik
2005-08-18 20:56             ` Robert A Duff [this message]
2005-08-18 22:01               ` Hyman Rosen
2005-08-19  2:35               ` Jeffrey R. Carter
2005-08-20 15:28                 ` Robert A Duff
2005-08-20 20:24                   ` Jeffrey R. Carter
2005-08-20 21:34                     ` Robert A Duff
2005-08-20 22:47                       ` Frank J. Lhota
2005-08-20 23:34                         ` Robert A Duff
2005-08-21 11:18                           ` Simon Wright
2005-08-21 16:59                             ` tmoran
2005-08-21 19:48                               ` Simon Wright
2005-08-21 16:07                           ` Frank J. Lhota
2005-08-21 16:23                           ` Martin Krischik
2005-08-21  1:12                       ` Björn Persson
2005-08-21  9:01                       ` Dmitry A. Kazakov
2005-08-21 16:14                       ` Martin Krischik
2005-08-21  4:02                     ` Larry Kilgallen
2005-08-19 12:34               ` Dr. Adrian Wrigley
2005-08-19 17:29                 ` Martin Krischik
2005-08-19 18:14                   ` Frank J. Lhota
2005-08-21 16:02                     ` Martin Krischik
2005-08-21 16:48                       ` Frank J. Lhota
2005-08-22 15:51                         ` Martin Krischik
2005-08-23  0:32                       ` Larry Elmore
     [not found]                         ` <h5dlg1tsie8n3ikirvbi508t9afobhctkj@4ax.com>
2005-08-23 18:09                           ` Martin Krischik
2005-08-23 19:50                             ` C history Björn Persson
2005-08-27 21:09                             ` Ada exception block does NOT work? Dave Thompson
2005-08-24  1:07                           ` Larry Elmore
2005-08-24  2:36                             ` Jeffrey R. Carter
2005-08-25  0:14                               ` Larry Elmore
2005-08-26  2:44                                 ` Jeffrey R. Carter
2005-08-24 16:44                             ` Martin Krischik
2005-08-22  8:12                     ` Hyman Rosen
2005-08-18 21:15             ` Robert A Duff
2005-08-19 12:00               ` Dmitry A. Kazakov
2005-08-17 20:24 ` Simon Wright
2005-08-18 19:36   ` Björn Persson
2005-08-18 21:07     ` Simon Wright
2005-08-22 10:47 ` bubble
replies disabled

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox