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-26 06:33:04 PST Path: archiver1.google.com!news1.google.com!newsfeed.stanford.edu!news-spur1.maxwell.syr.edu!news.maxwell.syr.edu!newsfeed.icl.net!newsfeed.fjserv.net!newsfeed.freenet.de!feed.news.nacamar.de!uninett.no!ntnu.no!not-for-mail From: Preben Randhol Newsgroups: comp.lang.ada Subject: Re: I/O - exception handling Date: Mon, 26 May 2003 13:33:04 +0000 (UTC) Organization: Norwegian university of science and technology Message-ID: References: NNTP-Posting-Host: kiuk0152.chembio.ntnu.no X-Trace: tyfon.itea.ntnu.no 1053955984 22382 129.241.83.78 (26 May 2003 13:33:04 GMT) X-Complaints-To: usenet@itea.ntnu.no NNTP-Posting-Date: Mon, 26 May 2003 13:33:04 +0000 (UTC) User-Agent: slrn/0.9.7.4 (Linux) Xref: archiver1.google.com comp.lang.ada:37782 Date: 2003-05-26T13:33:04+00:00 List-Id: Sergey Koshcheyev wrote: > Hi, > > I have this problem: I have a simple piece of code opening a file, reading a > few lines, then closing it. Now, I want this piece of code to be "safe", > i.e. not to leak any resources (the open file) in case of errors and not to > propagate any exceptions. What is the best style to write this code? [...] > begin > Open (File, Name => "test.txt", Mode => In_File); > Get_Line (File, S1); > Get_Line (File, S2); > Close (File); > > exception > when others => In stead of when others => why don't you check which exception occurred? You have Name_Error, Use_Error, Device_Error, End_Error etc... -- Preben Randhol http://www.pvv.org/~randhol/