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,5f260a1d9f0c280c X-Google-Attributes: gid103376,domainid0,public,usenet X-Google-Language: ENGLISH,ASCII-7-bit Path: g2news2.google.com!postnews.google.com!1g2000pre.googlegroups.com!not-for-mail From: Adam Beneschan Newsgroups: comp.lang.ada Subject: Re: Common exception handling Date: Tue, 26 Aug 2008 09:49:59 -0700 (PDT) Organization: http://groups.google.com Message-ID: <02ecfd28-f2f5-4323-962b-e75706e5a48a@1g2000pre.googlegroups.com> References: <88961e92-80a8-4e96-b231-9d67eca0adf5@v26g2000prm.googlegroups.com> <1d1a76fa-a537-4994-9578-7c7604b26ca2@w24g2000prd.googlegroups.com> <3263z19x9l0r.1bbulsb9dbwjm.dlg@40tude.net> NNTP-Posting-Host: 66.126.103.122 Mime-Version: 1.0 Content-Type: text/plain; charset=ISO-8859-1 Content-Transfer-Encoding: 7bit X-Trace: posting.google.com 1219769400 2675 127.0.0.1 (26 Aug 2008 16:50:00 GMT) X-Complaints-To: groups-abuse@google.com NNTP-Posting-Date: Tue, 26 Aug 2008 16:50:00 +0000 (UTC) Complaints-To: groups-abuse@google.com Injection-Info: 1g2000pre.googlegroups.com; posting-host=66.126.103.122; posting-account=duW0ogkAAABjRdnxgLGXDfna0Gc6XqmQ User-Agent: G2/1.0 X-HTTP-UserAgent: Mozilla/5.0 (X11; U; Linux x86_64; en-US; rv:1.7.12) Gecko/20050922 Fedora/1.7.12-1.3.1,gzip(gfe),gzip(gfe) Xref: g2news2.google.com comp.lang.ada:7525 Date: 2008-08-26T09:49:59-07:00 List-Id: On Aug 26, 8:10 am, "Dmitry A. Kazakov" wrote: > On Tue, 26 Aug 2008 07:43:20 -0700 (PDT), Adam Beneschan wrote: > > On Aug 26, 6:47 am, shaunpatter...@gmail.com wrote: > >> Yeah, it looks like the extra layer of exception handling is the only > >> way. I was hoping I could avoid that if possible. > > > No, I don't think it's the only way. I'm surprised no one has > > suggested this: > > > exception > > when E : others => > > Print_Test (Rec); > > declare > > use Ada.Exceptions; > > begin > > if Exception_Identity(E) = A'Identity then > > ... handling for A > > elsif Exception_Identity(E) = B'Identity then > > ... handling for B > > etc. > > else > > ... handling for other exceptions you didn't expect, > > ... but you certainly need to aware that it could > > ... happen > > raise; --maybe > > end if; > > end; > > Hmm, it looks quite ugly, IMO. Exception handler (case-like) is better > structured, cleaner, and possibly more efficient. > > --------- > If exceptions were first-class citizens allowed in case statements then: > > exception > when E : others => > Print_Test (Rec); > case E is -- This is not Ada, alas! > when A => ... > when B => ... > when others => ... > end case; Maybe this use of CASE should be allowed, even if we don't go all the way and make exceptions first-class entities in other ways. What does anyone else think... would it be a worthwhile feature to propose adding? Or is it just too "special" (if we added this, others would ask, well why shouldn't we allow CASE on a string, or a record, or a container, or just expand it using some user-specified relational operator so that we can use it for everything...)? -- Adam