title: Ada: Adding an exception in a separate procedure when reading a file
body: <p>This is a follow-up of this question:    <a href="https://stackoverflow.com/questions/9792230/ada-reading-from-a-file">Ada: reading from a file</a> .</p>
  
  <p>I would like to add an <code>exception</code> that checks if the file that I'm opening actually exists or not. I have made a <code>separate</code> procedure to avoid code clutter.</p>
  
  <p>Here is the main code <code>test_read.adb</code>:</p>
  
  <pre><code>with Ada.Text_IO; use Ada.Text_IO;
  with Ada.Long_Float_Text_IO;
  with Ada.Float_Text_IO;
  
  
  procedure Test_Read is
  
     Input_File    : File_Type;
     Value         : Long_Float;
  
  procedure Open_Data (File : in  Ada.Text_IO.File_Type; Name : in String) is separate;
  
  begin
  
     Ada.Text_IO.Open (File =&gt; Input_File, Mode =&gt; Ada.Text_IO.In_File, Name =&gt; "fx.txt");
  
     while not End_Of_File (Input_File) loop
        Ada.Long_Float_Text_IO.Get (File =&gt; Input_File, Item =&gt; Value);
        Ada.Long_Float_Text_IO.Put (Item =&gt; value, Fore =&gt; 3, Aft  =&gt; 5, Exp  =&gt; 0);
        Ada.Text_IO.New_Line;
     end loop;
     Ada.Text_IO.Close (File =&gt; Input_File);
  
  end Test_Read;
  </code></pre>
  
  <p>And here is the <code>separate</code> body <code>test_read-open_data.adb</code> of the procedure <code>Open_Data</code>:</p>
  
  <pre><code>separate(test_read)
  procedure Open_Data (File : in  out Ada.Text_IO.File_Type; 
                       Name : in String) is
  
     --this procedure prepares a file for reading
     begin
        begin
         Ada.Text_IO.Open
           (File =&gt; File,
            Mode =&gt; Ada.Text_IO.In_File,
            Name =&gt; Name);
         exception
         when Ada.Text_IO.Name_Error =&gt;
            Ada.Text_IO.Put(File =&gt; Standard_Error, Item =&gt; "File not found.");
        end;
  end Open_Data;
  </code></pre>
  
  <p>On compilation I get an error message in the <code>separate</code> body <code>test_read-open_data.adb</code>:</p>
  
  <pre><code>actual for "File" must be a variable
  </code></pre>
  
  <p>How to fix this?</p>
  
  <p>Thanks a lot...</p>
  
  <p><strong>Update</strong>:</p>
  
  <p>I have now made the following corrections.</p>
  
  <ol>
  <li><p>In <code>test_read.adb</code>, I now have <code>procedure Open_Data (File : in out  Ada.Text_IO.File_Type; Name : in String) is separate;</code> </p></li>
  <li><p>Updated the <em>definition</em> of the same <code>Open_Data</code> procedure in <code>test_read-open_data.adb</code>.</p></li>
  </ol>
  
  <p>The program compiles well though I do not see it catch the exception say if I renamed the file <code>fx.txt</code> to <code>fy.txt</code>. The error message I get is just</p>
  
  <pre><code>raised ADA.IO_EXCEPTIONS.NAME_ERROR : fx.txt: No such file or directory
  </code></pre>
  
  <p>So I do not get my own error message :<em>File not found</em>.</p>
  
  <p>What is still wrong?</p>