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 Path: g2news2.google.com!postnews.google.com!d77g2000hsb.googlegroups.com!not-for-mail From: Martin Newsgroups: comp.lang.ada Subject: Re: Common exception handling Date: Wed, 10 Sep 2008 15:51:37 -0700 (PDT) Organization: http://groups.google.com Message-ID: <94a89839-2e48-4c6e-922f-5d12584d28db@d77g2000hsb.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> <87eccd6a-2223-4295-86e5-54986fbf1530@s1g2000pra.googlegroups.com> NNTP-Posting-Host: 217.42.31.147 Mime-Version: 1.0 Content-Type: text/plain; charset=ISO-8859-1 Content-Transfer-Encoding: quoted-printable X-Trace: posting.google.com 1221087097 11877 127.0.0.1 (10 Sep 2008 22:51:37 GMT) X-Complaints-To: groups-abuse@google.com NNTP-Posting-Date: Wed, 10 Sep 2008 22:51:37 +0000 (UTC) Complaints-To: groups-abuse@google.com Injection-Info: d77g2000hsb.googlegroups.com; posting-host=217.42.31.147; posting-account=g4n69woAAACHKbpceNrvOhHWViIbdQ9G User-Agent: G2/1.0 X-HTTP-UserAgent: Mozilla/5.0 (Macintosh; U; Intel Mac OS X 10_5_4; en-us) AppleWebKit/525.18 (KHTML, like Gecko) Version/3.1.2 Safari/525.20.1,gzip(gfe),gzip(gfe) Xref: g2news2.google.com comp.lang.ada:7699 Date: 2008-09-10T15:51:37-07:00 List-Id: On Aug 29, 4:31=A0pm, Adam Beneschan wrote: > 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 on= ly > > > > way. I was hoping I could avoid that if possible. > > > > No, I don't think it's the only way. =A0I'm surprised no one has > > > suggested this: > > > > =A0 =A0exception > > > =A0 =A0 =A0 when E : others =3D> > > > =A0 =A0 =A0 =A0 =A0Print_Test (Rec); > > > =A0 =A0 =A0 =A0 =A0declare > > > =A0 =A0 =A0 =A0 =A0 =A0 =A0use Ada.Exceptions; > > > =A0 =A0 =A0 =A0 =A0begin > > > =A0 =A0 =A0 =A0 =A0 =A0 =A0if Exception_Identity(E) =3D A'Identity th= en > > > =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 ... handling for A > > > =A0 =A0 =A0 =A0 =A0 =A0 =A0elsif Exception_Identity(E) =3D B'Identity= then > > > =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 ... handling for B > > > =A0 =A0 =A0 =A0 =A0 =A0 =A0etc. > > > =A0 =A0 =A0 =A0 =A0 =A0 =A0else > > > =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 ... handling for other exceptions you= didn't expect, > > > =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 ... but you certainly need to aware t= hat it could > > > =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 ... happen > > > =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 raise; =A0--maybe > > > =A0 =A0 =A0 =A0 =A0 =A0 =A0end if; > > > =A0 =A0 =A0 =A0 =A0end; > > > > =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 -- 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. =A0But I > wasn't being funny here. =A0Although 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. =A0Another problem with the nested exception handler solution > is that it could incur extra overhead since exception raising isn't > necessarily cheap. =A0That shouldn't matter in most cases, but sometimes > it might. =A0So 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. > > =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0-- Ada= m Sorry - back again! It was mostly the (to my eyes) sheer "ugliness" of the if..elsif..elsif..end if;. I find these sorts of structures very hard to follow (was there a sneeky 'and then ' snuck into one of the branches??? -- Martin