Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • Home
  • SEARCH
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 7672617
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 31, 20262026-05-31T16:19:38+00:00 2026-05-31T16:19:38+00:00

This is a follow up of this [post] Ada: Adding an exception in a

  • 0

This is a follow up of this [post] Ada: Adding an exception in a separate procedure when reading a file

When my code below opens a file that doesn’t exist, instead of throwing a ADA.IO_EXCEPTIONS.NAME_ERROR, it is throwing a ADA.IO_EXCEPTIONS.STATUS_ERROR.

Below are the codes.

Main file: test_read.adb:

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 out  Ada.Text_IO.File_Type; Name : in String) is separate;

begin

   Open_Data (File => Input_File, Name => "fx.txt");

   while not End_Of_File (Input_File) loop
      Ada.Long_Float_Text_IO.Get (File => Input_File, Item => value);
      Ada.Long_Float_Text_IO.Put (Item => value, Fore => 3, Aft  => 5, Exp  => 0);
   Ada.Text_IO.New_Line;
   end loop;
    Ada.Text_IO.Close (File => Input_File);

end Test_Read;

And the separate procedure body test_read-open_data.adb:

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 => File,
            Mode => Ada.Text_IO.In_File,
            Name => Name);
      exception
         when Ada.Text_IO.Name_Error =>
         Ada.Text_IO.Put(File => Standard_Error, Item => "****File not found....****");
   end;
end Open_Data;

The error message that is thrown:

****File not found....****

Execution terminated by unhandled exception
Exception name: ADA.IO_EXCEPTIONS.STATUS_ERROR
Message: file not open
Call stack traceback locations:
0x40bf0f 0x40ead0 0x424b08 0x424e4a 0x4010b4 0x401146 0x7c817075
[2012-03-21 13:45:44] process exited with status 1 (elapsed time: 00.13s)

I have tried a few things:

  1. Put with Ada.IO_Exceptions; in test_read.adb and put when Ada.IO_Exceptions.Name_Error => instead of when Ada.Text_IO.Name_Error => in test_read-open_data.adb. But there is no change.

  2. In test_read-open_data.adb, I changed the line Mode => Ada.Text_IO.In_File to make it become Mode => Ada.Text_IO.Out_File as shown below:

    Ada.Text_IO.Open
    (File => File,
    Mode => Ada.Text_IO.Out_File,
    Name => Name);

But there is no improvement.

So how to get the right ADA.IO_EXCEPTIONS.NAME_ERROR?

A related question:

What’s the difference between Ada.Text_IO.Name_Error and ADA.IO_EXCEPTIONS.NAME_ERROR? In my program I want to be informed when the file of name fx.txt does not exist. Which one of these two exceptions is appropriate?

Thanks a lot

UPDATE (Latest Codes)

Here are my updated codes:

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;
   Success       : Boolean;

procedure Open_Data (File : in out  Ada.Text_IO.File_Type; Name : in String; Success : out Boolean) is separate;

begin

   Open_Data (File => Input_File, Name => "fx.txt", Success => Success);
   if not Success then
      return;
   end if;

   while not End_Of_File (Input_File) loop
      Ada.Long_Float_Text_IO.Get (File => Input_File, Item => value);
      Ada.Long_Float_Text_IO.Put (Item => value, Fore => 3, Aft  => 5, Exp  => 0);
      Ada.Text_IO.New_Line;
   end loop;
   Ada.Text_IO.Close (File => Input_File);
   Ada.Text_IO.Put_Line (Item => "Reading file success: " & Boolean'Image (Success));

end Test_Read;

and the separate procedure:

separate (test_read)

procedure Open_Data (File : in out  Ada.Text_IO.File_Type;
                 Name : in String; Success : out Boolean) is

   --this procedure prepares a file for reading
     begin
      Success := True;
      begin
         Ada.Text_IO.Open
           (File => File,
            Mode => Ada.Text_IO.Out_File,
            Name => Name);
      exception
         when Ada.Text_IO.Name_Error  =>
         Success := False;   
         Ada.Text_IO.Put (File => Standard_Error, Item => "****File not found....****");
      end;
end Open_Data;

On compiling with file fx.txt present, I get:

Execution terminated by unhandled exception
Exception name: ADA.IO_EXCEPTIONS.MODE_ERROR
Message: file not readable
Call stack traceback locations:
0x40bf2b 0x40ead0 0x424b58 0x424f5a 0x4010b4 0x401146 0x7c817075
[2012-03-22 08:39:39] process exited with status 1 (elapsed time: 00.14s)

And the contents of the file fx.txt **get erased and its contents are not displayed on running the program**

On compiling with file fx.txt renamed to fy.txt, I get:

****File not found....****
[2012-03-22 08:45:31] process terminated successfully (elapsed time: 00.13s)

So what went wrong?

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-31T16:19:39+00:00Added an answer on May 31, 2026 at 4:19 pm

    The output is just what I would expect: a Name_Error is thrown and caught, File not found is printed, and the program continues. Open_Data does not tell its caller that the file has not been opened, and the subsequent operations on the file trigger a Status_Error. You could, for example, add a Success : out Boolean to Open_Data‘s parameters, or raise an exception (one of your own, or simply re-raise Name_Error.

    E.g.

    Open_Data (File => Input_File, Name => "fx.txt", Success => Success);
    if not Success then
       return;
    end if;
    
    while not End_Of_File (Input_File) loop
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

This question is a follow-up of the post at Ada file operation: instantiation and
This is a follow-up question related to my previous post . Below is a
This is a follow-up of the post at Ada: plotting 2d graphs . I
I have an issue I have this jQuery code: $(document).ready(function(){ $(#follow).click(function(){ $.ajax({ type: 'POST',
This is follow up post where I'm having a problem where my php code
This post if a follow-up question to mt previous post: Android RESTful Web application
Trying to follow this example. (Section String sorting...) Is there anything obvious that would
I have a bunch of python methods that follow this pattern: def delete_session(guid): conn
I follow this post What is the simplest and most robust way to get
I have follow this post to make ImageButton in android android image button The

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.