Ada 95 Quality and Style Guide Chapter 7

Chapter 7: Portability - TOC - 7.7 INPUT/OUTPUT

7.7.5 Current Error Files

guideline

  • Consider using Current_Error and Set_Error for run-time error messages.

  • example

    with Ada.Text_IO;
    
    ...
    
    begin
       Ada.Text_IO.Open (File => Configuration_File,
                         Mode => Ada.Text_IO.In_File,
                         Name => Configuration_File_Name);
    exception
       when Ada.Text_IO.Name_Error =>
          Ada.Text_IO.Put_Line (File => Ada.Text_IO.Standard_Error,
                                Item => "Can't open configuration file.");
          ...
    end;
    
    

    rationale

    The package Text_IO includes the concept of a current error file. You should report errors to the user through the associated subprograms Current_Error and Set_Error instead of the standard output facilities. In interactive applications, using the Text_IO error facilities increases the portability of your user interface.

    notes

    In a program with multiple tasks for I/O, you need to be careful of two or more tasks trying to set Current_Input, Current_Output, or Current_Error. The potential problem lies in unprotected updates to the "shared" state associated with a package, in this case, the package Text_IO. Guidelines 6.1.1 and 6.2.4 discuss the related issues of unprotected shared variables.


    < Previous Page Search Contents Index Next Page >
    1 2 3 4 5 6 7 8 9 10 11
    TOC TOC TOC TOC TOC TOC TOC TOC TOC TOC TOC
    Appendix References Bibliography