On this page
std/oserrors
Source EditThe std/oserrors
module implements OS error reporting.
Imports
Types
Procs
-
proc newOSError(errorCode: OSErrorCode; additionalInfo = ""): owned(ref OSError) {. noinline, ...raises: [], tags: [], forbids: [].}
-
Creates a new OSError exception.
The
errorCode
will determine the message, osErrorMsg proc will be used to get this message.The error code can be retrieved using the osLastError proc.
If the error code is
0
or an error message could not be retrieved, the messageunknown OS error
will be used.See also:
Source Edit -
proc osErrorMsg(errorCode: OSErrorCode): string {....raises: [], tags: [], forbids: [].}
-
Converts an OS error code into a human readable string.
The error code can be retrieved using the osLastError proc.
If conversion fails, or
errorCode
is0
then""
will be returned.See also:
Example:
Source Editwhen defined(linux): assert osErrorMsg(OSErrorCode(0)) == "" assert osErrorMsg(OSErrorCode(1)) == "Operation not permitted" assert osErrorMsg(OSErrorCode(2)) == "No such file or directory"
-
proc osLastError(): OSErrorCode {.sideEffect, ...raises: [], tags: [], forbids: [].}
-
Retrieves the last operating system error code.
This procedure is useful in the event when an OS call fails. In that case this procedure will return the error code describing the reason why the OS call failed. The
OSErrorMsg
procedure can then be used to convert this code into a string.Warning: The behaviour of this procedure varies between Windows and POSIX systems. On Windows some OS calls can reset the error code to0
causing this procedure to return0
. It is therefore advised to call this procedure immediately after an OS call fails. On POSIX systems this is not a problem.See also:
Source Edit -
proc raiseOSError(errorCode: OSErrorCode; additionalInfo = "") {.noinline, ...raises: [OSError], tags: [], forbids: [].}
-
Raises an OSError exception.
Read the description of the newOSError proc to learn how the exception object is created.
Source Edit
© 2006–2024 Andreas Rumpf
Licensed under the MIT License.
https://nim-lang.org/docs/oserrors.html