comp.lang.ada
 help / color / mirror / Atom feed
From: pipex!zaphod.crihan.fr!vishnu.jussieu.fr!univ-lyon1.fr!scsing.switch.ch!e pflnews!disuns2.epfl.ch!lglsun!madmats@uunet.uu.net  (Mats Weber)
Subject: Re: Comparison of Ada and C++ exceptions?
Date: 16 Sep 93 08:45:34 GMT	[thread overview]
Message-ID: <1993Sep16.100759@lglsun.epfl.ch> (raw)

In article <275plh$smn@aggedor.rmit.OZ.AU>, Dale Stanbrough <dale@goanna.cs.rmi
t.edu.au> writes:
|> Recently I had reason to look at C++'s exception handling. I noticed that
|> each
|> exception can have associated with it some data (user defined), such as a
|> string, a pointer - in fact any object the programmer wants. 
|> 
|> I don't think Ada9x's exceptions have any such feature, and I was
|> wondering
|> what the general feeling about this was.
|> 

I think such a feature would be very useful, especially when
interfacing large non-Ada based systems, such as POSIX, where there
are many error situations that cannot easily be mapped onto
exceptions.

In POSIX, if each system error situation is mapped onto an Ada
exception, then programmers will often have to write huge exception
choices in their handlers, such as the following (which requires
reading the documentation for each possible call, even if the details
of the error doesn't matter):

exception
   when POSIX_Exceptions.IO_Error |
        POSIX_Exceptions.Invalid_File_Number |
	POSIX_Exceptions.xxx |
	POSIX_Exceptions.yyy |
	POSIX_Exceptions.zzz =>
      Do_Something;

Note: I am probably not up to date on how the POSIX exceptions are
organized, but this is just an example.

There should be some way of handling all these exceptions together,
with a single choice in the handler. A proposal for this (hierarchical
exceptions) was in a previous version of the draft 9X mapping, but was
removed. I think this proposal was very good.

Being able to attach a parameter to exceptions solves the problem in
the previous example, too.  POSIX, for example, coud then have

   type POSIX_Error_Code is (IO_Error, Invalid_File_Number, ...);
   POSIX_Error : exception (Code : POSIX_Error_Code);
	
Where each exception would be parameterized with a value of the type
POSIX_Error_Code, Which would allow handling POSIX exceptions with a
single choice and sepcializing exception handlers only when necessary.

-- 
Mats Weber
Software Engineering Lab
Swiss Federal Institute of Technology
CH-1015 Lausanne
Switzerland
e-mail: mats.weber@lglsun.epfl.ch

             reply	other threads:[~1993-09-16  8:45 UTC|newest]

Thread overview: 5+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
1993-09-16  8:45 pipex!zaphod.crihan.fr!vishnu.jussieu.fr!univ-lyon1.fr!scsing.switch.ch!e [this message]
  -- strict thread matches above, loose matches on Subject: below --
1993-09-19 21:39 Comparison of Ada and C++ exceptions? agate!usenet.ins.cwru.edu!magnus.acs.ohio-state.edu!math.ohio-state.edu!d
1993-09-16 14:28 David Emery
1993-09-16  6:20 Dag Bruck
1993-09-15  1:03 munnari.oz.au!bruce.cs.monash.edu.au!monu6!aggedor.rmit.OZ.AU!root
replies disabled

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