EOF Exception Example
MC logo
 

EOF Exception Example

Ada Code Examples


<<OO Stack Driver Download Data Exception Example>>
--
-- This simply reads the lines of its input file and uses the End_Error
-- exception to detect EOF.
--
with Ada.Text_IO; use Ada.Text_IO;
procedure ReadOut is
   S: String(1..100);   -- Input line (up to 100 chars)
   N: Integer;          -- Number of characters read.
begin
   -- Issue the lovely decoration.
   Put_Line("-----------------------------------------------------" &
            "-----------");

   -- Copy lines like there's no tomorrow.
   loop
      Get_Line(S, N);
      Put_Line(S(1..N));
   end loop;

   exception
   when End_Error =>
      -- When reaching end of file, issue the closing lovely decoration and
      -- return from the procedure.
      Put_Line("-----------------------------------------------------" &
               "-----------");
      return;
end ReadOut;
<<OO Stack Driver Data Exception Example>>