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!s1g2000pra.googlegroups.com!not-for-mail From: Adam Beneschan Newsgroups: comp.lang.ada Subject: Re: Common exception handling Date: Fri, 29 Aug 2008 08:31:03 -0700 (PDT) Organization: http://groups.google.com Message-ID: <87eccd6a-2223-4295-86e5-54986fbf1530@s1g2000pra.googlegroups.com> References: <88961e92-80a8-4e96-b231-9d67eca0adf5@v26g2000prm.googlegroups.com> <1d1a76fa-a537-4994-9578-7c7604b26ca2@w24g2000prd.googlegroups.com> <2c0a5d86-82cf-4538-87d4-6733eaca8784@r66g2000hsg.googlegroups.com> 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 1220023864 8930 127.0.0.1 (29 Aug 2008 15:31:04 GMT) X-Complaints-To: groups-abuse@google.com NNTP-Posting-Date: Fri, 29 Aug 2008 15:31:04 +0000 (UTC) Complaints-To: groups-abuse@google.com Injection-Info: s1g2000pra.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:7547 Date: 2008-08-29T08:31:03-07:00 List-Id: On Aug 29, 1:32 am, Martin wrote: > On 26 Aug, 15:43, 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; > > > -- Adam > > Surely you missed a smiley off this suggestion!!! :-) Well, I do often post silly things without smileys and assume everyone is astute enough to figure out that I was trying to be funny. But I wasn't being funny here. Although the above looks somewhat ugly, I can imagine that a solution of this sort may be entirely appropriate in some cases. Suppose, for example, that the common code isn't just at the beginning, but is also at the end, or maybe even in the middle; the nested exception handler/reraise solution might not be so clean in that case. Another problem with the nested exception handler solution is that it could incur extra overhead since exception raising isn't necessarily cheap. That shouldn't matter in most cases, but sometimes it might. So I don't understand why the above is so ridiculous as to merit the comment you gave. I would say, though, that if your exception-handling code gets that complex, it might be time to think about declaring just one exception and a separate data structure for passing additional exception info around. -- Adam