Function DosError() Foundation

Retrieves the last operating system error code.

DosError( [<nNewOsErrorID>] ) --> nErrorID
When the optional argument <nNewOsErrorID> is specified, its value is set for return by subsequent DosError() calls until a new operating system error occurs. The value of <nNewOsErrorID> must be numeric and contain a valid error code.

DosError() returns an integer numeric value which represents an error code of the operating system.


The function name DosError does not designate the operating system DOS but is translated as Disk-Operating-System-Error. The function returns a numeric code. In 32bit operating systems there are many more error codes than in the operating system DOS. However, the first 88 error codes of the operating systems DOS, OS/2, Windows 9x and Windows NT are the same.

DosError() is an error function which returns the last error code of the operating system. An error code is set whenever a runtime error occurs. DosError() is often used in runtime error code blocks activated by the function ErrorBlock(). Ordinarily DosError() is checked after a RECOVER statement. The value of the function remains until a new runtime error occurs or it is redefined using <nNewOsErrorID>. When there is not an operating system error code for a failed operation, the function DosError() returns the value zero. When an error occurs with the low level file functions, the function FError() returns the same value as DosError().

The textual description of the error code can be retrieved by the function DosErrorMessage().

Under OS/2 a description of an error code can be retrieved by entering HELP <nErrorCode> on the command line.

Use DosError() for error handling
// The example shows the basic construction of an error 
// handler for runtime errors using BEGIN SEQUENCE..END 
// The function DosError() is used in the RECOVER section 
// to determine an error code. After the occurrence of the 
// runtime error, DosError() returns the error code for 
// the error which most recently occurred. 

   LOCAL oError 
   LOCAL bErrorBlock 
   bErrorBlock := ErrorBlock( {|e| Break(e) } ) 
      DosError(55)          // determine current error code 
      ? DosError()          // result: 55 

      USE abcdefgh NEW      // create runtime error (OS error) 


      ? DosError()          // result: 2 
                            // means: file not found 
      IF DosError() == 2 
         ? "The file", oError:Filename, "does not exist!" 



If you see anything in the documentation that is not correct, does not match your experience with the particular feature or requires further clarification, please use this form to report a documentation issue.