From mboxrd@z Thu Jan 1 00:00:00 1970 X-Spam-Checker-Version: SpamAssassin 3.4.4 (2020-01-24) on polar.synack.me X-Spam-Level: X-Spam-Status: No, score=-1.9 required=5.0 tests=BAYES_00 autolearn=ham autolearn_force=no version=3.4.4 X-Google-Thread: 103376,703c4f68db81387d X-Google-Thread: 109fba,703c4f68db81387d X-Google-Thread: 115aec,703c4f68db81387d X-Google-Thread: f43e6,703c4f68db81387d X-Google-Attributes: gid103376,gid109fba,gid115aec,gidf43e6,public X-Google-Language: ENGLISH,ASCII-7-bit Path: g2news1.google.com!news4.google.com!news.glorb.com!tudelft.nl!transit0.news.tiscali.nl!tiscali!transit1.news.tiscali.nl!dreader2.news.tiscali.nl!not-for-mail Newsgroups: comp.lang.ada,comp.lang.c++,comp.realtime,comp.software-eng Subject: Class hierarchy of exceptions (Ada, C++) References: <4229bad9$0$1019$afc38c87@news.optusnet.com.au> <1110032222.447846.167060@g14g2000cwa.googlegroups.com> <871xau9nlh.fsf@insalien.org> <3SjWd.103128$Vf.3969241@news000.worldonline.dk> <87r7iu85lf.fsf@insalien.org> <1110052142.832650@athnrd02> <1110284070.410136.205090@o13g2000cwo.googlegroups.com> <395uqaF5rhu2mU1@individual.net> <1111607633.301232.62490@z14g2000cwz.googlegroups.com> From: Ludovic Brenta Date: Sat, 26 Mar 2005 11:19:18 +0100 Message-ID: <87oed6wvyx.fsf_-_@insalien.org> User-Agent: Gnus/5.1007 (Gnus v5.10.7) Emacs/21.3 (gnu/linux) Cancel-Lock: sha1:p8P+mTxaIflwxPNeO/d0DQImAbM= MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Organization: Tiscali bv NNTP-Posting-Date: 26 Mar 2005 11:19:25 CET NNTP-Posting-Host: 83.134.243.37 X-Trace: 1111832365 dreader2.news.tiscali.nl 44080 83.134.243.37:34891 X-Complaints-To: abuse@tiscali.nl Xref: g2news1.google.com comp.lang.ada:10023 comp.lang.c++:47329 comp.realtime:1741 comp.software-eng:5358 Date: 2005-03-26T11:19:25+01:00 List-Id: Robert A Duff writes: > Well, actually, during the Ada 9X design I tried to push for a > class-hierarchy of exceptions. I don't like every detail of the way > C++ does it, but at least in *this* regard, it's better than Ada. > > Jerry Coffin is wrong that Ada does not allow attaching information > to exception, by the way. Ada allows attaching Strings, which is > admittedly a kludge. Using the class-hierarchy, as Jerry advocates, > would be cleaner, and type safe. I kind of like Ada exceptions as they are now. Because one cannot carry much information in them (apart from the kluge you mentioned), one tends not to rely on them for the normal flow of operations. I have seen Java programs that would rely on exceptions for all kinds of things, leading to spaghetti code. In C++ I find it a bit odd that I can throw and catch an entire hash table as an exception if I want to. The C++ way of catching all exceptions of a class and its derived classes can lead to confusion. One can have multiple exception handlers for the same exception and it may not be immediately obvious to the reader which one is called. I see this as a maintenance problem. Another concern of mine with exception classes is that they'd have to be allocated on the heap. There are situations where there is no heap to allocate from, or where dynamic allocation is forbidden. I think it necessary to provide a simple exception mechanism that does not require any dynamic allocation, much less dynamic dispatching. Perhaps a good middle-ground would be an addition to Ada along the lines of: package Ada.Exceptions.Extra is type Extra_Information is abstract tagged null record; procedure Raise_Exception (E : in Exception_Id; Information : in Extra_Information'Class); function Exception_Information (X : Exception_Occurrence) return Extra_Information'Class; end Ada.Exceptions.Extra; Programs that want to carry rich information with exceptions would be allowed to do so, while "pragma Restrictions (No_Dispatch)" or "No_Dynamic_Allocation" would guarantee, to those interested, that no such thing happens. I am aware that all this would require the compiler to provide two exception mechanisms and two kinds of Exception_Occurrences, so I may have opened a can of worms here. Just thinking out loud :) -- Ludovic Brenta.