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=-0.9 required=5.0 tests=BAYES_00,FORGED_GMAIL_RCVD, FREEMAIL_FROM autolearn=no autolearn_force=no version=3.4.4 X-Google-Thread: 103376,c71bf3c5adc59b21 X-Google-Attributes: gid103376,domainid0,public,usenet X-Google-Language: ENGLISH,ASCII-7-bit Path: g2news2.google.com!postnews.google.com!j22g2000hsf.googlegroups.com!not-for-mail From: amado.alves@gmail.com Newsgroups: comp.lang.ada Subject: Re: Opening a file vs. creating if not yet exists Date: Tue, 19 Aug 2008 05:58:09 -0700 (PDT) Organization: http://groups.google.com Message-ID: <186cc4de-61fc-44d7-ab2e-456e538531f6@j22g2000hsf.googlegroups.com> References: NNTP-Posting-Host: 88.214.136.214 Mime-Version: 1.0 Content-Type: text/plain; charset=ISO-8859-1 Content-Transfer-Encoding: 7bit X-Trace: posting.google.com 1219150690 2461 127.0.0.1 (19 Aug 2008 12:58:10 GMT) X-Complaints-To: groups-abuse@google.com NNTP-Posting-Date: Tue, 19 Aug 2008 12:58:10 +0000 (UTC) Complaints-To: groups-abuse@google.com Injection-Info: j22g2000hsf.googlegroups.com; posting-host=88.214.136.214; posting-account=3cDqWgoAAAAZXc8D3pDqwa77IryJ2nnY User-Agent: G2/1.0 X-HTTP-UserAgent: Mozilla/4.0 (compatible; MSIE 7.0; Windows NT 6.0; SLCC1; .NET CLR 2.0.50727; Media Center PC 5.0; .NET CLR 3.0.04506; .NET CLR 1.1.4322),gzip(gfe),gzip(gfe) Xref: g2news2.google.com comp.lang.ada:7377 Date: 2008-08-19T05:58:09-07:00 List-Id: > begin > Open (File, Append_File, "file.txt"); > exception > when Name_Error => > Create (File, Append_File, "file.txt"); > end; > > Is the above idiomatic (ie. well understood and accepted as common > practice)? There seems to be two schools of though regarding the use of exceptions for logic. Some of us accept the idiom happily. But probably the most conventional school is the "don't" So in this particular case and if you are using Ada 2005 then you might consider the uncontroversial if Ada.Directories.File_Exists (Filename) then Open (...) else Create (...) end if;