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,FREEMAIL_FROM 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 12:01:02 PST Path: archiver1.google.com!news1.google.com!newsfeed.stanford.edu!logbridge.uoregon.edu!news-FFM2.ecrc.net!news.cesnet.cz!crax.cesnet.cz!news.felk.cvut.cz!not-for-mail From: "Sergey Koshcheyev" Newsgroups: comp.lang.ada Subject: Re: I/O - exception handling Date: Mon, 26 May 2003 20:48:31 +0200 Organization: Czech Technical University Message-ID: References: NNTP-Posting-Host: r2c113.mistral.cz X-Trace: ns.felk.cvut.cz 1053974905 9382 62.245.66.113 (26 May 2003 18:48:25 GMT) X-Complaints-To: usenet@ns.felk.cvut.cz NNTP-Posting-Date: Mon, 26 May 2003 18:48:25 +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:37811 Date: 2003-05-26T20:48:31+02:00 List-Id: "Preben Randhol" wrote in message news:slrnbd4m0j.4gn.randhol+abuse@kiuk0152.chembio.ntnu.no... > Sergey Koshcheyev wrote: > >> Safe_Close (File); > > > > I'd change the line above to just "Close (File);", to have the opportunity > > to handle any error raised by Close. > > Sure, I thought you didn't want though. Well, in this case I get error checking for free, so why not :-) > > I thought of this solution, but here the problem is code duplication. In > > this case it doesn't matter, but what if there were several files? You'd > > have a procedure Close_All and a procedure Safe_Close_All, which would both > > contain similar code. > > Please explain, I don't follow you. OK, let's imagine I have two files and also want to handle several types of errors: procedure Two_Files_IO is File1, File2 : File_Type; begin Open (File1); Open (File2); -- Read from File1 into File2 or something like that -- Normal clean-up, error-checked Close (File1); Close (File2); exception when Some_Error => -- Report Safe_Close (File1); Safe_Close (File2); when Another_Error => -- Report Safe_Close (File1); Safe_Close (File2); when others => -- "Safe" clean-up Safe_Close (File1); Safe_Close (File2); end Two_Files_IO; Now, this is of course extreme. So I'd probably rewrite it as follows: procedure Two_Files_IO is ... begin begin Open (File1); Open (File2); -- Read from two files exception when Some_Error => -- Report null; when Another_Error => -- Report null; when others => null; end; Safe_Close (File1); Safe_Close (File2); end Two_Files_IO; This is probably going to be my ideal solution, now that I think of it. Here I have given up the error-checking during the "normal clean-up", but the C++ people do it too, so it's going to be OK with me :-) Now of course, the fact that Close raises exceptions seems sort of useless, even unhelpful. What am I supposed to do with a file, if I can't close it? Hm, maybe I should write my own Sergey.Text_IO :-) > Well why don't you use Finalize ? I just find it too restricted to be worth the hassle ("derive from a type", "declare at a library level", etc., etc. ... why not just "for X'Finalize use Finalize_X"? - the compiler knows when the objects are to be finalized, anyway). Besides, it's not my fault that Text_IO.File_Type isn't Limited_Controlled already. Hm, why stop at Text_IO, maybe I should write an Ada++? :-) Just kidding... Anyway, since I have arrived at a solution that pleases me, I think I'll close this discussion now. Thanks to all who replied, Sergey.