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: g2news1.google.com!postnews.google.com!w24g2000prd.googlegroups.com!not-for-mail From: Martin Newsgroups: comp.lang.ada Subject: Re: Common exception handling Date: Tue, 26 Aug 2008 05:39:23 -0700 (PDT) Organization: http://groups.google.com Message-ID: <1d1a76fa-a537-4994-9578-7c7604b26ca2@w24g2000prd.googlegroups.com> References: <88961e92-80a8-4e96-b231-9d67eca0adf5@v26g2000prm.googlegroups.com> NNTP-Posting-Host: 20.133.0.8 Mime-Version: 1.0 Content-Type: text/plain; charset=ISO-8859-1 Content-Transfer-Encoding: quoted-printable X-Trace: posting.google.com 1219754363 21442 127.0.0.1 (26 Aug 2008 12:39:23 GMT) X-Complaints-To: groups-abuse@google.com NNTP-Posting-Date: Tue, 26 Aug 2008 12:39:23 +0000 (UTC) Complaints-To: groups-abuse@google.com Injection-Info: w24g2000prd.googlegroups.com; posting-host=20.133.0.8; posting-account=g4n69woAAACHKbpceNrvOhHWViIbdQ9G User-Agent: G2/1.0 X-HTTP-UserAgent: Mozilla/5.0 (Windows; U; Windows NT 5.1; en-GB; rv:1.9.0.1) Gecko/2008070208 Firefox/3.0.1,gzip(gfe),gzip(gfe) Xref: g2news1.google.com comp.lang.ada:1790 Date: 2008-08-26T05:39:23-07:00 List-Id: On Aug 26, 1:17=A0pm, shaunpatter...@gmail.com wrote: [snip] > I'd like to not duplicate the Print_Test in each situation. =A0Is there > an easy way Just add an extra level of exception handling and re-raise the exception when you've done the common bit: with Ada.Text_IO; use Ada.Text_IO; procedure Throw_Three is type Record_Type is record I : Integer; end record; procedure Print_Test (Rec : Record_Type) is begin Put_Line ("Print_Test:" & Integer'Image (Rec.I)); end Print_Test; A, B, C : exception; procedure Test (Rec : Record_Type) is begin begin case Rec.I is when 1 =3D> raise A; when 2 =3D> raise B; when 3 =3D> raise C; when others =3D> raise Program_Error; end case; exception when others =3D> Print_Test (Rec); -- Common bit raise; -- Re-raise the same exception end; exception when A =3D> Put_Line ("A"); when B =3D> Put_Line ("B"); when C =3D> Put_Line ("C"); when others =3D> Put_Line ("others"); end Test; begin for I in 1 .. 4 loop Test (Rec =3D> (I =3D> I)); end loop; end Throw_Three;