comp.lang.ada
 help / color / mirror / Atom feed
From: amado.alves@gmail.com
Subject: Re: Opening a file vs. creating if not yet exists
Date: Tue, 19 Aug 2008 05:58:09 -0700 (PDT)
Date: 2008-08-19T05:58:09-07:00	[thread overview]
Message-ID: <186cc4de-61fc-44d7-ab2e-456e538531f6@j22g2000hsf.googlegroups.com> (raw)
In-Reply-To: af68d80f-0f42-4524-a963-80c91b427ad9@k7g2000hsd.googlegroups.com

> 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;



  parent reply	other threads:[~2008-08-19 12:58 UTC|newest]

Thread overview: 8+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2008-08-18 15:03 Opening a file vs. creating if not yet exists Maciej Sobczak
2008-08-19 12:36 ` Rob Norris
2008-08-19 12:58 ` amado.alves [this message]
2008-08-19 14:23 ` Jacob Sparre Andersen
2008-08-19 14:58   ` Maciej Sobczak
2008-08-21 15:41     ` Martin Krischik
2008-08-21 21:06       ` Maciej Sobczak
2008-08-21 15:42     ` Martin Krischik
replies disabled

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox