RAD Studio VCL Reference
ContentsIndex
PreviousUpNext
EInOutError Class

EInOutError is the exception class for file input/output errors.

Pascal
EInOutError = class(Exception);
C++
class EInOutError : public Exception;

EInOutError is raised when an file input/output error occurs, provided I/O checking is enabled.

Note: In Delphi code, use the $I+ directive to enable I/O checking. If an I/O error occurs while this directive is disabled, the application must call IOResult to clear the error.
Note: In C++ programs, I/O checking is a project option.
The error code is available in the ErrorCode class member. Error codes are come in ranges: 0-99 (native OS errors) 

Error codes in the range 0-99 represent OS error conditions, which are different for Windows and Linux. Refer to the OS documentation for complete error summaries. The SysErrorMessage function returns descriptive text for OS errors. 

Here are some common OS I/O errors, arranged by rough equivalents in Linux and Windows: 

LinuxWindows

Linux 
 
Windows 
 
Error Code  
Description  
Error Code  
Description  
2  
No such file or directory  
2  
File not found  
3  
Path not found  
 
 
5  
I/O Error  
 
 
13  
Permission denied  
5  
Access denied  
20  
Not a directory  
 
 
21  
Is a directory  
 
 
32  
Sharing violation  
 
 
Error codes in the range 100 to 149 represent error conditions raised by CLX. Here are the CLX I/O error codes:  
 
 
 

 

Error code 
Meaning 
100  
End of File  
101  
Disk Full  
102  
File variable not assigned  
103  
File not open  
104  
File not open for input  
105  
File not open for output  
106  
Error in formatted input  
107  
File already open  

 

Delphi Examples: 

{
Click the button to open a TOpenDialog, then select a file 
to delete.
}

procedure TForm1.Button1Click(Sender: TObject);
var
  F: Textfile;
begin
  OpenDialog1.Title := 'Delete File';
  if OpenDialog1.Execute then
  begin
    AssignFile(F, OpenDialog1.FileName);
    try
      Reset(F);
      if MessageDlg('Erase ' + OpenDialog1.FileName + '?',
        mtConfirmation, [mbYes, mbNo], 0) = mrYes then
      begin
        CloseFile(F);
        Erase(F);
      end;
    except
      on EInOutError do
        MessageDlg('File I/O error.', mtError, [mbOk], 0);
    end;
  end;
end;

 

Copyright(C) 2009 Embarcadero Technologies, Inc. All Rights Reserved.
What do you think about this topic? Send feedback!