comp.lang.ada
 help / color / mirror / Atom feed
* Exception types?
@ 1998-06-08  0:00 Brian Rogoff
  1998-06-08  0:00 ` Matthew Heaney
  1998-06-10  0:00 ` Michel Gauthier
  0 siblings, 2 replies; 13+ messages in thread
From: Brian Rogoff @ 1998-06-08  0:00 UTC (permalink / raw)



One of the things that always bothered me about exceptions in Ada 
is that they are not really integrated into the type system, for example, 
they are not part of a generic signature package. I looked through the 
Ada 95 and Ada 83 Rationales to try to find a discussion of this topic, 
but I couldn't find one. Is there some record available? 

-- Brian






^ permalink raw reply	[flat|nested] 13+ messages in thread

* Re: Exception types?
  1998-06-08  0:00 Exception types? Brian Rogoff
@ 1998-06-08  0:00 ` Matthew Heaney
  1998-06-09  0:00   ` Brian Rogoff
  1998-06-10  0:00 ` Michel Gauthier
  1 sibling, 1 reply; 13+ messages in thread
From: Matthew Heaney @ 1998-06-08  0:00 UTC (permalink / raw)



Brian Rogoff <bpr@shell5.ba.best.com> writes:

> One of the things that always bothered me about exceptions in Ada 
> is that they are not really integrated into the type system, for example, 
> they are not part of a generic signature package. I looked through the 
> Ada 95 and Ada 83 Rationales to try to find a discussion of this topic, 
> but I couldn't find one. Is there some record available? 

Mats Weber pointed this out too, in his PhD thesis.

You can work around this feature by importing a package that contains an
exception declaration.  This is how Text_IO works, by importing package
IO_Exceptions.

Sort of like:

package Compiler_Exceptions is

   Syntax_Error : exception;

end;

generic
   procedure Scan (...);  
   --
   -- Raises Compiler_Exceptions.Syntax_Error.
...
package GP is ...;

An then the actual subprogram can import the Compiler_Exceptions package
too.

Actually, in Ada 95 this can be integrated with the package hierarchy.
This is how Ada.Strings... works.  All the exceptions are declared in
the root package.







^ permalink raw reply	[flat|nested] 13+ messages in thread

* Re: Exception types?
  1998-06-08  0:00 ` Matthew Heaney
@ 1998-06-09  0:00   ` Brian Rogoff
  1998-06-15  0:00     ` Mats Weber
       [not found]     ` <3586FFC0.5FEC1CBC@fiu.edu>
  0 siblings, 2 replies; 13+ messages in thread
From: Brian Rogoff @ 1998-06-09  0:00 UTC (permalink / raw)



On 8 Jun 1998, Matthew Heaney wrote:
> Brian Rogoff <bpr@shell5.ba.best.com> writes:
> 
> > One of the things that always bothered me about exceptions in Ada 
> > is that they are not really integrated into the type system, for example, 
> > they are not part of a generic signature package. I looked through the 
> > Ada 95 and Ada 83 Rationales to try to find a discussion of this topic, 
> > but I couldn't find one. Is there some record available? 
> 
> Mats Weber pointed this out too, in his PhD thesis.

Yes, I read that, and Magnus Kempe's paper on generic signature packages. 
It is also noticeable to anyone who uses any of the various ML module 
systems, which are similar to Ada except that exceptions are part of a 
module signature.

> You can work around this feature by importing a package that contains an
> exception declaration.  This is how Text_IO works, by importing package
> IO_Exceptions.
>
> ... workaround snipped ...

It isn't really a workaround, as you haven't really parameterized the
package by an exception, and you can't pass that package as a generic 
formal package parameter. Mats workaround involved passing a success/failure 
function (an exception "wrapper"), which is a little better in the
particular case I'm interested in. There are a few workarounds which
involve "programmer discipline" but I was wondering what the thinking was
behind not having typed exceptions to begin with in Ada 83. I imagine the 
reason for not having them in Ada 95 could be upward compatibility. 

I suppose this "feature" of the language will discourage the use of
exceptions in control flow, which will greatly please the Eiffel 
fanat^H^H^H^H^H advocates among us.

-- Brian





^ permalink raw reply	[flat|nested] 13+ messages in thread

* Re: Exception types?
  1998-06-08  0:00 Exception types? Brian Rogoff
  1998-06-08  0:00 ` Matthew Heaney
@ 1998-06-10  0:00 ` Michel Gauthier
  1998-06-11  0:00   ` Brian Rogoff
  1 sibling, 1 reply; 13+ messages in thread
From: Michel Gauthier @ 1998-06-10  0:00 UTC (permalink / raw)



In article <Pine.BSF.3.96.980608083034.15065A-100000@shell5.ba.best.com>,
Brian Rogoff <bpr@shell5.ba.best.com> wrote:

>>  One of the things that always bothered me about exceptions in Ada 
>>  is that they are not really integrated into the type system, for example, 
>>  they are not part of a generic signature package. I looked through the 
>>  Ada 95 and Ada 83 Rationales to try to find a discussion of this topic, 
>>  but I couldn't find one. Is there some record available? 

You can find some ideas about it in a paper I wrote for ACM Ada Letters, 
perhaps April 1995 (don't flame if erroneous).

The main idea is that you can deal with something very close to 
"exception type" by using Ada.Exceptions.Exception_ID.
  You can use it as subprogram parameter, generic parameter, 
record component,... and then raise or handle it. The syntax is of 
course different from exceptions, but the behaviour is similar.

----------          ----------          ----------          ---------- 
Michel Gauthier / Laboratoire d'informatique
123 avenue Albert Thomas / F-87060 Limoges
telephone + 33 5 55 43 69 73
fax +33 5 55 43 69 77
----------          ----------          ----------          ----------
Hein, quoi, quelle annee dix-neuf cent nonante dix ?
What exactly about year nineteen ninety ten ?
----------          ----------          ----------          ----------




^ permalink raw reply	[flat|nested] 13+ messages in thread

* Re: Exception types?
  1998-06-10  0:00 ` Michel Gauthier
@ 1998-06-11  0:00   ` Brian Rogoff
  0 siblings, 0 replies; 13+ messages in thread
From: Brian Rogoff @ 1998-06-11  0:00 UTC (permalink / raw)



On 10 Jun 1998, Michel Gauthier wrote:

> In article <Pine.BSF.3.96.980608083034.15065A-100000@shell5.ba.best.com>,
> Brian Rogoff <bpr@shell5.ba.best.com> wrote:
> 
> >>  One of the things that always bothered me about exceptions in Ada 
> >>  is that they are not really integrated into the type system, for example, 
> >>  they are not part of a generic signature package. I looked through the 
> >>  Ada 95 and Ada 83 Rationales to try to find a discussion of this topic, 
> >>  but I couldn't find one. Is there some record available? 
> 
> You can find some ideas about it in a paper I wrote for ACM Ada Letters, 
> perhaps April 1995 (don't flame if erroneous).

July/August 1996, on scanning? That was a nice paper, though I disagree
with your assertion that Ada 95 has nothing new for generic scanning. 
Signature packages allow you to decouple scans from scanning
representations using only generics. But I digress...
 
> The main idea is that you can deal with something very close to 
> "exception type" by using Ada.Exceptions.Exception_ID.

In the paper I just mentioned, you used Ada.Exceptions.Exception_Occurrence, 
which is not really analogous to exception type; Exception_ID is much 
better. I can even compare them, thats interesting. This definitely seems 
like the way to go. I'll try it and see how things work.

-- Brian

>   You can use it as subprogram parameter, generic parameter, 
> record component,... and then raise or handle it. The syntax is of 
> course different from exceptions, but the behaviour is similar.

> ----------          ----------          ----------          ---------- 
> Michel Gauthier / Laboratoire d'informatique
> 123 avenue Albert Thomas / F-87060 Limoges
> telephone + 33 5 55 43 69 73
> fax +33 5 55 43 69 77
> ----------          ----------          ----------          ----------
> Hein, quoi, quelle annee dix-neuf cent nonante dix ?
> What exactly about year nineteen ninety ten ?
> ----------          ----------          ----------          ----------
> 
> 






^ permalink raw reply	[flat|nested] 13+ messages in thread

* Re: Exception types?
  1998-06-09  0:00   ` Brian Rogoff
@ 1998-06-15  0:00     ` Mats Weber
  1998-06-15  0:00       ` Corey Ashford
  1998-06-15  0:00       ` Brian Rogoff
       [not found]     ` <3586FFC0.5FEC1CBC@fiu.edu>
  1 sibling, 2 replies; 13+ messages in thread
From: Mats Weber @ 1998-06-15  0:00 UTC (permalink / raw)
  To: Brian Rogoff


Brian Rogoff wrote:

> It isn't really a workaround, as you haven't really parameterized the
> package by an exception, and you can't pass that package as a generic
> formal package parameter. Mats workaround involved passing a success/failure
> function (an exception "wrapper"), which is a little better in the
> particular case I'm interested in.

This is not true, or at least inaccurate (I don't know what you mean by "a
success/failure function" or an exception "wrapper").

My proposal is to add parameters to exceptions, as in Modula-3 (and in Ada 95,
with the IMO ridiculous limitation to strings of 200 characters).

In one of the 9X Mapping documents, there was an extension to Ada's exceptions
that essentially made them part of the type system and you could derive them
much as you can derive types, thus creating a hierarchy of exceptions.

> [...] but I was wondering what the thinking was
> behind not having typed exceptions to begin with in Ada 83. I imagine the
> reason for not having them in Ada 95 could be upward compatibility.

The proposal was in the mapping, but was removed. Maybe someone who
participated actively in the language design can tell us why ?




^ permalink raw reply	[flat|nested] 13+ messages in thread

* Re: Exception types?
  1998-06-15  0:00     ` Mats Weber
  1998-06-15  0:00       ` Corey Ashford
@ 1998-06-15  0:00       ` Brian Rogoff
  1998-06-21  0:00         ` Robert Dewar
  1998-06-21  0:00         ` Robert Dewar
  1 sibling, 2 replies; 13+ messages in thread
From: Brian Rogoff @ 1998-06-15  0:00 UTC (permalink / raw)
  To: Mats Weber


On Mon, 15 Jun 1998, Mats Weber wrote:
> Brian Rogoff wrote:
> > It isn't really a workaround, as you haven't really parameterized the
> > package by an exception, and you can't pass that package as a generic
> > formal package parameter. Mats workaround involved passing a success/failure
> > function (an exception "wrapper"), which is a little better in the
> > particular case I'm interested in.
> 
> This is not true, or at least inaccurate (I don't know what you mean by "a
> success/failure function" or an exception "wrapper").

On page 9 of your thesis, you discuss one Ada 83 workaround to the lack of 
exception types, that is passing around a function (End_Of_File) and
assuming that it is checked at places where an exception might be raised. 
That is what I meant by "your workaround", not your actual language
extension proposals.

> My proposal is to add parameters to exceptions, as in Modula-3 (and in Ada 95,
> with the IMO ridiculous limitation to strings of 200 characters).
> 
> In one of the 9X Mapping documents, there was an extension to Ada's exceptions
> that essentially made them part of the type system and you could derive them
> much as you can derive types, thus creating a hierarchy of exceptions.
>

This would be very useful, and would bring one more surly language
construct under the dominance of the package system. 

-- Brian


> > [...] but I was wondering what the thinking was
> > behind not having typed exceptions to begin with in Ada 83. I imagine the
> > reason for not having them in Ada 95 could be upward compatibility.
> 
> The proposal was in the mapping, but was removed. Maybe someone who
> participated actively in the language design can tell us why ?
> 
>





^ permalink raw reply	[flat|nested] 13+ messages in thread

* Re: Exception types?
  1998-06-15  0:00     ` Mats Weber
@ 1998-06-15  0:00       ` Corey Ashford
  1998-06-15  0:00       ` Brian Rogoff
  1 sibling, 0 replies; 13+ messages in thread
From: Corey Ashford @ 1998-06-15  0:00 UTC (permalink / raw)




Mats Weber wrote in message <3584F47B.3ADF7442@elca-matrix.ch>...
>Brian Rogoff wrote:
>
>> It isn't really a workaround, as you haven't really parameterized the
>> package by an exception, and you can't pass that package as a generic
>> formal package parameter. Mats workaround involved passing a
success/failure
>> function (an exception "wrapper"), which is a little better in the
>> particular case I'm interested in.
>
>This is not true, or at least inaccurate (I don't know what you mean by "a
>success/failure function" or an exception "wrapper").
>
>My proposal is to add parameters to exceptions, as in Modula-3 (and in Ada
95,
>with the IMO ridiculous limitation to strings of 200 characters).

You've misread the 200 character limitation in Ada95. The LRM doesn't allow
implementations to limit the string length unless you're using the
Ada.Exceptions.Save_Occurrence *procedure*  (as opposed to the function).
In all other
cases, the string can be of arbitrary length.

>
>In one of the 9X Mapping documents, there was an extension to Ada's
exceptions
>that essentially made them part of the type system and you could derive
them
>much as you can derive types, thus creating a hierarchy of exceptions.
>
>> [...] but I was wondering what the thinking was
>> behind not having typed exceptions to begin with in Ada 83. I imagine the
>> reason for not having them in Ada 95 could be upward compatibility.
>
>The proposal was in the mapping, but was removed. Maybe someone who
>participated actively in the language design can tell us why ?

You can throw an Ada.Exceptions.Exception_Id type via the
Ada.Exceptions.Raise_Exception procedure. This allows a program to throw
dynamically
named exceptions (because Exception_Id's can be passed around).

Hope this helps

- Corey







^ permalink raw reply	[flat|nested] 13+ messages in thread

* Re: Exception types?
       [not found]     ` <3586FFC0.5FEC1CBC@fiu.edu>
@ 1998-06-17  0:00       ` Jean-Pierre Rosen
  1998-06-18  0:00         ` Matthew Heaney
  0 siblings, 1 reply; 13+ messages in thread
From: Jean-Pierre Rosen @ 1998-06-17  0:00 UTC (permalink / raw)



The big issue with passing exceptions to generics, exception types, etc. is
that you don't want two handlers for the same exception.
Imagine (not Ada);

generic
   E1 : exception;
   E2 : exception;
procedure P;

procedure P is
    ..
begin
   ...
exception
   when E1 => ...
   when E2 => ...
end;

Then, an instanciation like:
   procedure Q is new P (Constraint_Error, Constraint_Error);
would end up with two different handlers for the same exception !

Therefore it is clear that *catching* an exception can only be done with
statically defined exception names. Therefore, the only remaining
interesting thing that could be done with "exception variables" would be
raising. But this is now available with the package Ada.Exceptions.
Therefore, there is no need to add these features to the language.

--
----------------------------------------------------------------------------
                  J-P. Rosen (Rosen.Adalog@wanadoo.fr)
      Visit Adalog's web site at http://perso.wanadoo.fr/adalog

Luis Espinal a �crit dans le message <3586FFC0.5FEC1CBC@fiu.edu>...
>Yeah, that's a question I've asked myself when I learned Ada at FIU in
>1995; there
>must have been some reason to leave out (or avoid) typed exceptions,
>passing
>exceptions to packages. I just can't think of one, but again, I'm still
>learning;
>I really would like to know whether this omission of typed exceptions is
>a
>feature promoting better software engineering or an "accident". Does
>anybody
>would know of a possible answer?
>
>If you would like to satisfy my curiosity, then many thanks:)
>
>Luis Espinal.





^ permalink raw reply	[flat|nested] 13+ messages in thread

* Re: Exception types?
  1998-06-17  0:00       ` Jean-Pierre Rosen
@ 1998-06-18  0:00         ` Matthew Heaney
  1998-06-19  0:00           ` Jean-Pierre Rosen
  0 siblings, 1 reply; 13+ messages in thread
From: Matthew Heaney @ 1998-06-18  0:00 UTC (permalink / raw)



"Jean-Pierre Rosen" <rosen.adalog@wanadoo.fr> writes:

> Therefore it is clear that *catching* an exception can only be done with
> statically defined exception names. Therefore, the only remaining
> interesting thing that could be done with "exception variables" would be
> raising. But this is now available with the package Ada.Exceptions.
> Therefore, there is no need to add these features to the language.

True, but you gotta admit the syntax for raising an exception with a
message attached is a bit heavy:

   if <I/O failed> then
      Raise_Exception (IO_Error'Identity, "CRC check failed");
   end if;

It just seems hipper to be able to say

   if <I/O Failed> then
      raise IO_Error ("CRC check failed");
   end if;

I'm sure the language design team considered things like this, and am
equally sure they had good reasons to reject it.  Nice to fancy, though,
huh?




^ permalink raw reply	[flat|nested] 13+ messages in thread

* Re: Exception types?
  1998-06-18  0:00         ` Matthew Heaney
@ 1998-06-19  0:00           ` Jean-Pierre Rosen
  0 siblings, 0 replies; 13+ messages in thread
From: Jean-Pierre Rosen @ 1998-06-19  0:00 UTC (permalink / raw)



Matthew Heaney a �crit dans le message ...
>"Jean-Pierre Rosen" <rosen.adalog@wanadoo.fr> writes:
>
>> Therefore it is clear that *catching* an exception can only be done with
>> statically defined exception names. Therefore, the only remaining
>> interesting thing that could be done with "exception variables" would be
>> raising. But this is now available with the package Ada.Exceptions.
>> Therefore, there is no need to add these features to the language.
>
>True, but you gotta admit the syntax for raising an exception with a
>message attached is a bit heavy:
>
>   if <I/O failed> then
>      Raise_Exception (IO_Error'Identity, "CRC check failed");
>   end if;
>
>It just seems hipper to be able to say
>
>   if <I/O Failed> then
>      raise IO_Error ("CRC check failed");
>   end if;
>
>I'm sure the language design team considered things like this, and am
>equally sure they had good reasons to reject it.  Nice to fancy, though,
>huh?

True, but I would qualify this as a "nice to have" feature.
A lot of "nice to have" features were considere in the design of Ada 95.
Most of them were rejected on the ground that, even if each of the features
would require -say- one week to implement, test, etc. , when doing the
total, it would have slowed down the appearance of compilers by *years*.
--
----------------------------------------------------------------------------
                  J-P. Rosen (Rosen.Adalog@wanadoo.fr)
      Visit Adalog's web site at http://perso.wanadoo.fr/adalog






^ permalink raw reply	[flat|nested] 13+ messages in thread

* Re: Exception types?
  1998-06-15  0:00       ` Brian Rogoff
@ 1998-06-21  0:00         ` Robert Dewar
  1998-06-21  0:00         ` Robert Dewar
  1 sibling, 0 replies; 13+ messages in thread
From: Robert Dewar @ 1998-06-21  0:00 UTC (permalink / raw)



<<> The proposal was in the mapping, but was removed. Maybe someone who
> participated actively in the language design can tell us why ?
>>


There was a LOT of stuff in the mapping documents. There was virtually
unanimous agreement (with only the design team dissenting) that in
aggregate the design was far too extensive. So it had to be cut back.
This feature in particular was one that introduced a lot of implementation
complexity for insufficient gain, and there was general agreement that
it had too low a value-to-effort ratio. Note that this does not mean
that in isolation this feature was "bad" (there is nothing wrong per se
with the last straw on the camel's back :-)

Note that I think the general level of change turned out about right. Most
(but still not all) Ada vendors have managed to upgrade to Ada 95 (GNAT
acted as a useful nudge). We still have at least one vendor remainin
committed to Ada 83, and one major vendor that dropped out completely
(Digital) and one of the reasons for that dropout was (as Bevin has
noted), the extent of the change. We also had one Ada technology drop
out of site (the old Alsys technology) as a direct result of the fact
that the change was too extensive.

SO I think we compromised at a reasonable level. We lost some implementations
but kept the majority. If we had accepted everything in the mapping team's
design document, I think we would have far fewer Ada 95 compilers on the
market today (perhaps none).

That being said, at this stage, it is very worthwhile to go back and look
at some of the (very good) suggestions that were dropped. Another example
of a feature worth looking at for example is the extension of 'Class to
non-tagged types. There are many others.

At this stage, it would be definitely interesting on a research project
basis to attempt adding some of these features to experimental versions
of GNAT (this is one of the advantages of having the sources available!)






^ permalink raw reply	[flat|nested] 13+ messages in thread

* Re: Exception types?
  1998-06-15  0:00       ` Brian Rogoff
  1998-06-21  0:00         ` Robert Dewar
@ 1998-06-21  0:00         ` Robert Dewar
  1 sibling, 0 replies; 13+ messages in thread
From: Robert Dewar @ 1998-06-21  0:00 UTC (permalink / raw)



Mats said

<<My proposal is to add parameters to exceptions, as in Modula-3 (and in Ada 95,
with the IMO ridiculous limitation to strings of 200 characters).
>>


I think this limitation is quite reasonable, given the intended use, which
is simply to pass a short identifying message along. It is of course trivial
to eliminate this limitation in an implementation, but only at the expense
of implicit heap use, which is generally undesirable.

(especially if the exception in question is Storage_Error!)





^ permalink raw reply	[flat|nested] 13+ messages in thread

end of thread, other threads:[~1998-06-21  0:00 UTC | newest]

Thread overview: 13+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
1998-06-08  0:00 Exception types? Brian Rogoff
1998-06-08  0:00 ` Matthew Heaney
1998-06-09  0:00   ` Brian Rogoff
1998-06-15  0:00     ` Mats Weber
1998-06-15  0:00       ` Corey Ashford
1998-06-15  0:00       ` Brian Rogoff
1998-06-21  0:00         ` Robert Dewar
1998-06-21  0:00         ` Robert Dewar
     [not found]     ` <3586FFC0.5FEC1CBC@fiu.edu>
1998-06-17  0:00       ` Jean-Pierre Rosen
1998-06-18  0:00         ` Matthew Heaney
1998-06-19  0:00           ` Jean-Pierre Rosen
1998-06-10  0:00 ` Michel Gauthier
1998-06-11  0:00   ` Brian Rogoff

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