From: Martin <martin.dowie@btopenworld.com>
Subject: Re: Common exception handling
Date: Tue, 26 Aug 2008 05:39:23 -0700 (PDT)
Date: 2008-08-26T05:39:23-07:00 [thread overview]
Message-ID: <1d1a76fa-a537-4994-9578-7c7604b26ca2@w24g2000prd.googlegroups.com> (raw)
In-Reply-To: 88961e92-80a8-4e96-b231-9d67eca0adf5@v26g2000prm.googlegroups.com
On Aug 26, 1:17 pm, shaunpatter...@gmail.com wrote:
[snip]
> I'd like to not duplicate the Print_Test in each situation. Is 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 => raise A;
when 2 => raise B;
when 3 => raise C;
when others => raise Program_Error;
end case;
exception
when others =>
Print_Test (Rec); -- Common bit
raise; -- Re-raise the same exception
end;
exception
when A =>
Put_Line ("A");
when B =>
Put_Line ("B");
when C =>
Put_Line ("C");
when others =>
Put_Line ("others");
end Test;
begin
for I in 1 .. 4 loop
Test (Rec => (I => I));
end loop;
end Throw_Three;
next prev parent reply other threads:[~2008-08-26 12:39 UTC|newest]
Thread overview: 18+ messages / expand[flat|nested] mbox.gz Atom feed top
2008-08-26 12:17 Common exception handling shaunpatterson
2008-08-26 12:37 ` Ludovic Brenta
2008-08-26 12:39 ` Martin [this message]
2008-08-26 12:48 ` Ludovic Brenta
2008-08-26 12:58 ` Martin
2008-08-26 13:47 ` shaunpatterson
2008-08-26 14:43 ` Adam Beneschan
2008-08-26 15:10 ` Dmitry A. Kazakov
2008-08-26 16:49 ` Adam Beneschan
2008-08-26 19:14 ` Dmitry A. Kazakov
2008-08-26 20:22 ` Maciej Sobczak
2008-08-27 8:16 ` Dmitry A. Kazakov
2008-08-27 9:20 ` Georg Bauhaus
2008-08-29 8:32 ` Martin
2008-08-29 15:31 ` Adam Beneschan
2008-09-10 22:51 ` Martin
2008-09-11 14:57 ` Adam Beneschan
2008-08-26 15:18 ` Jean-Pierre Rosen
replies disabled
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox