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-Language: ENGLISH,ASCII-7-bit X-Google-Thread: 103376,d8a4797a79f9c90f X-Google-Attributes: gid103376,public X-Google-ArrivalTime: 2003-05-27 05:01:06 PST Path: archiver1.google.com!news1.google.com!newsfeed.stanford.edu!pln-w!extra.newsguy.com!lotsanews.com!cyclone-sf.pbi.net!151.164.30.35!cyclone.swbell.net!newsfeed1.easynews.com!newsfeed2.easynews.com!easynews.com!easynews!newsfeed.news2me.com!newsfeed.icl.net!newsfeed.fjserv.net!colt.net!news-lond.gip.net!news-FFM2.ecrc.net!news.iks-jena.de!not-for-mail From: Lutz Donnerhacke Newsgroups: comp.lang.ada Subject: Re: I/O - exception handling Date: Tue, 27 May 2003 12:01:03 +0000 (UTC) Organization: IKS GmbH Jena Message-ID: References: NNTP-Posting-Host: taranis.iks-jena.de X-Trace: branwen.iks-jena.de 1054036863 20503 217.17.192.37 (27 May 2003 12:01:03 GMT) X-Complaints-To: usenet@iks-jena.de NNTP-Posting-Date: Tue, 27 May 2003 12:01:03 +0000 (UTC) User-Agent: slrn/0.9.7.4 (Linux) Xref: archiver1.google.com comp.lang.ada:37830 Date: 2003-05-27T12:01:03+00:00 List-Id: * Preben Randhol wrote: > procedure One_Of_Your_Procedures_That_Open_Files > is > begin > Open (File, Name => "test.txt", Mode => In_File); > Get_Line (File, S1); > Get_Line (File, S2); > > Safe_Close (File); > exception > when others => > Safe_Close (File); > end Read_Something; > > Now you can use the Safe_Close in any function you like. Why not: procedure Read_Something is File : File_Type; begin Open (File, Name => "test.txt", Mode => In_File); declare S1, S2 : String (1 .. 90); begin Get_Line (File, S1); Get_Line (File, S2); exception when others => Print_Line("ERROR!"); end; Close (File); exception when others => Print_Line("ERROR!"); end Read_Something; Close will not be called if Open failed.