OS.File.Error

Instances of OS.File.Error are used by OS.File to notify of file-related errors.

Using OS.File.Error

Example: Finding out whether the problem is due to a file that does not exist

try {
   let file = OS.File.open("myfile.txt");
   // ...
} catch (ex) {
   if (ex instanceof OS.File.Error && ex.becauseNoSuchFile) {
      // The file does not exist
  }
}

Global object OS.File.Error

Methods overview

The following functions are utility functions that may be used to construct instances of OS.File.Error, setting the platform-specific error number.

Error closed()
Error exists()

Methods

OS.File.Error.closed()

Return an error representing the fact that a file is closed.

OS.File.Error.exists()

Return an error representing the fact that a file exists.

Instances of OS.File.Error

In case of any I/O error, the functions of OS.File raise instances of OS.File.Error. These exceptions hold both a human-readable error message detailing the I/O error and attributes to help determining the cause of the error.

Cross-platform attributes

operation The human-readable name of the failed operation.
becauseExists true if the operation failed because a file or directory exists, false otherwise.
becauseNoSuchFile true if the operation failed because a file or directory does not exist, false otherwise.
becauseClosed true if the operation failed because a file or directory is closed, false otherwise.

Platform-specific attributes

unixErrno (defined under Unix only) The system error number (errno) for the error. For more details, you may compare it with the error constants of OS.Constants.libc.E*.
winLastError (defined under Windows only) The system error number (GetLastError) for the error. For more details, you may compare it with the error constants of OS.Constants.Win.ERROR_*.

 

Document Tags and Contributors

 Contributors to this page: teoli, jukbot, AmrEldib, Yoric
 Last updated by: teoli,