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.1 required=5.0 tests=BAYES_00, PP_MIME_FAKE_ASCII_TEXT autolearn=no autolearn_force=no version=3.4.4 X-Google-Language: ENGLISH,ASCII X-Google-Thread: 103376,d8a4797a79f9c90f X-Google-Attributes: gid103376,public X-Google-ArrivalTime: 2003-05-26 08:10:04 PST Path: archiver1.google.com!news1.google.com!newsfeed.stanford.edu!news.ems.psu.edu!news.litech.org!news-spur1.maxwell.syr.edu!news.maxwell.syr.edu!oleane.net!oleane!nnrp.oleane.net!skymaster!nobody From: "Jean-Pierre Rosen" Newsgroups: comp.lang.ada Subject: Re: I/O - exception handling Date: Mon, 26 May 2003 16:52:39 +0200 Organization: Adalog Message-ID: References: NNTP-Posting-Host: mailhost.axlog.fr X-Trace: s1.read.news.oleane.net 1053961603 18262 195.25.228.57 (26 May 2003 15:06:43 GMT) X-Complaints-To: abuse@oleane.net NNTP-Posting-Date: Mon, 26 May 2003 15:06:43 +0000 (UTC) X-Priority: 3 X-MSMail-Priority: Normal X-Newsreader: Microsoft Outlook Express 6.00.2800.1158 X-MimeOLE: Produced By Microsoft MimeOLE V6.00.2800.1165 Xref: archiver1.google.com comp.lang.ada:37791 Date: 2003-05-26T16:52:39+02:00 List-Id: "Sergey Koshcheyev" a �crit dans le message de news:bat3ee$2ec$1@ns.felk.cvut.cz... [..] > procedure Read_Something (...) is > use Ada.Text_IO; > use Ada.Strings.Unbounded; > use Ada.Strings.Unbounded.Text_IO; > -- GNAT-specific package, I believe > > File : File_Type; > S1, S2 : Unbounded_String; > > begin > Open (File, Name => "test.txt", Mode => In_File); > Get_Line (File, S1); > Get_Line (File, S2); > Close (File); > > exception > when others => > if Is_Open (File) then > begin > Close (File); > exception > -- Close can raise exceptions too! > when others => null; > end; > end if; > end Read_Something; Doing so will make the exception disappear. You exception handler should rather read: exception when others => if Is_Open (File) then begin Close (File); exception -- Close can raise exceptions too! when others => null; end; end if; raise; -- Reraise the original exception, even if you had another exception at close end Read_Something; > However, this looks ugly to me, since I have to close the file in two > places, and also guard for exceptions while handling exceptions. Is there a > better solution or is this sort of thing OK in the Ada way? > > Sergey. > >