comp.lang.ada
 help / color / mirror / Atom feed
From: bobduff@world.std.com (Robert A Duff)
Subject: Re: question on exceptions
Date: 1996/11/06
Date: 1996-11-06T00:00:00+00:00	[thread overview]
Message-ID: <E0GJHH.5Jy@world.std.com> (raw)
In-Reply-To: 55l00n$alv@ash.ridgecrest.ca.us


In article <55l00n$alv@ash.ridgecrest.ca.us>,
Do-While Jones <do_while@lo-pan.ridgecrest.ca.us> wrote:
>The moral of the story is that the exception is simply a flag that tells
>you something has gone wrong.  If you take care to save the pertinent
>values before the exception is raised, and if you include a mechanism to
>retrieve those values when an exception has been detected, you have all
>the information you need. 

In a multi-tasking program, you would probably want to store this
information in a task attribute.

I still think that some other languages do it better (more type safety)
than Ada.  What I want is to declare what sort of information is
attached to a particular exception name.  Then the handler knows what
type of information is attached, and references to this information can
be type checked.  C++, Java, CLOS, etc have this capability.

While your solution works, it isn't quite as safe.  For example, a
handler for X might try to grab information that is only associated with
exception Y.  Or somebody might evilly call the function to get the
extra information when not in an exception handler at all, when the
information isn't available.  Or an exception handler might call a
procedure that internally raises-then-handles an exception, thus
overwriting the information -- you have to be careful to grab the
information before doing anything else in the exception handler that
might invalidate the information.  You could write the
information-getting function to detect these errors at run time, but it
would be slightly nicer to have compile-time error detection.  You can
write comments in the code explaining the proper use of this function,
but it would be slightly nicer to have that information encoded in the
program itself, in a standard way.

By the way, during the design of Ada 9X, it was suggested that we have
functions for querying things like the Current_Exception_Name and
Current_Exception_String.  However, the design team rejected this idea
for the reasons explained above -- presumably the semantics of calling
these at the wrong time would be "erroneous", which is bad.  My main
complaint about the Ada 95 design for this stuff is that the information
associated with an exception *must* be of type String.  I suppose you
can encode whatever information you want in a string, but not with type
safety.

- Bob




  reply	other threads:[~1996-11-06  0:00 UTC|newest]

Thread overview: 11+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
1996-11-02  0:00 question on exceptions Michiel Perdeck
1996-11-03  0:00 ` Robert A Duff
1996-11-03  0:00 ` Laurent Guerby
1996-11-04  0:00   ` Do-While Jones
1996-11-06  0:00     ` Robert A Duff [this message]
1996-11-07  0:00       ` Tucker Taft
1996-11-08  0:00         ` Robert A Duff
1996-11-08  0:00       ` Robert Dewar
1996-11-09  0:00         ` Tucker Taft
     [not found]           ` <E0Mr58.D00@world.std.com>
1996-11-09  0:00             ` Robert Dewar
1996-11-04  0:00 ` Michel Gauthier
replies disabled

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