diff options
Diffstat (limited to 'lib/pure/includes/oserr.nim')
-rw-r--r-- | lib/pure/includes/oserr.nim | 15 |
1 files changed, 12 insertions, 3 deletions
diff --git a/lib/pure/includes/oserr.nim b/lib/pure/includes/oserr.nim index 68ce5d95f..34d8d0085 100644 --- a/lib/pure/includes/oserr.nim +++ b/lib/pure/includes/oserr.nim @@ -57,8 +57,10 @@ proc osErrorMsg*(errorCode: OSErrorCode): string = if errorCode != OSErrorCode(0'i32): result = $c_strerror(errorCode.int32) -proc raiseOSError*(errorCode: OSErrorCode; additionalInfo = "") {.noinline.} = - ## Raises an `OSError exception <system.html#OSError>`_. +proc newOSError*( + errorCode: OSErrorCode, additionalInfo = "" +): owned(ref OSError) {.noinline.} = + ## Creates a new `OSError exception <system.html#OSError>`_. ## ## The ``errorCode`` will determine the ## message, `osErrorMsg proc <#osErrorMsg,OSErrorCode>`_ will be used @@ -82,7 +84,14 @@ proc raiseOSError*(errorCode: OSErrorCode; additionalInfo = "") {.noinline.} = e.msg.addQuoted additionalInfo if e.msg == "": e.msg = "unknown OS error" - raise e + return e + +proc raiseOSError*(errorCode: OSErrorCode, additionalInfo = "") {.noinline.} = + ## Raises an `OSError exception <system.html#OSError>`_. + ## + ## Read the description of the `newOSError proc <#newOSError,OSErrorCode,string>`_ to learn + ## how the exception object is created. + raise newOSError(errorCode, additionalInfo) {.push stackTrace:off.} proc osLastError*(): OSErrorCode {.sideEffect.} = |