Error -> Defect for defects (#13908)
* Error -> Defect for defects The distinction between Error and Defect is subjective, context-dependent and somewhat arbitrary, so when looking at an exception, it's hard to guess what it is - this happens often when looking at a `raises` list _without_ opening the corresponding definition and digging through layers of inheritance. With the help of a little consistency in naming, it's at least possible to start disentangling the two error types and the standard lib can set a good example here.
This commit is contained in:
parent
cd9af6b804
commit
7d6cbf290a
92 changed files with 323 additions and 300 deletions
|
|
@ -204,14 +204,14 @@ proc `[]`*(x: Any, i: int): Any =
|
|||
of tyArray:
|
||||
var bs = x.rawType.base.size
|
||||
if i >=% x.rawType.size div bs:
|
||||
raise newException(IndexError, formatErrorIndexBound(i, x.rawType.size div bs))
|
||||
raise newException(IndexDefect, formatErrorIndexBound(i, x.rawType.size div bs))
|
||||
return newAny(x.value +!! i*bs, x.rawType.base)
|
||||
of tySequence:
|
||||
var s = cast[ppointer](x.value)[]
|
||||
if s == nil: raise newException(ValueError, "sequence is nil")
|
||||
var bs = x.rawType.base.size
|
||||
if i >=% cast[PGenSeq](s).len:
|
||||
raise newException(IndexError, formatErrorIndexBound(i, cast[PGenSeq](s).len-1))
|
||||
raise newException(IndexDefect, formatErrorIndexBound(i, cast[PGenSeq](s).len-1))
|
||||
return newAny(s +!! (align(GenericSeqSize, x.rawType.base.align)+i*bs), x.rawType.base)
|
||||
else: assert false
|
||||
|
||||
|
|
@ -221,7 +221,7 @@ proc `[]=`*(x: Any, i: int, y: Any) =
|
|||
of tyArray:
|
||||
var bs = x.rawType.base.size
|
||||
if i >=% x.rawType.size div bs:
|
||||
raise newException(IndexError, formatErrorIndexBound(i, x.rawType.size div bs))
|
||||
raise newException(IndexDefect, formatErrorIndexBound(i, x.rawType.size div bs))
|
||||
assert y.rawType == x.rawType.base
|
||||
genericAssign(x.value +!! i*bs, y.value, y.rawType)
|
||||
of tySequence:
|
||||
|
|
@ -229,7 +229,7 @@ proc `[]=`*(x: Any, i: int, y: Any) =
|
|||
if s == nil: raise newException(ValueError, "sequence is nil")
|
||||
var bs = x.rawType.base.size
|
||||
if i >=% cast[PGenSeq](s).len:
|
||||
raise newException(IndexError, formatErrorIndexBound(i, cast[PGenSeq](s).len-1))
|
||||
raise newException(IndexDefect, formatErrorIndexBound(i, cast[PGenSeq](s).len-1))
|
||||
assert y.rawType == x.rawType.base
|
||||
genericAssign(s +!! (align(GenericSeqSize, x.rawType.base.align)+i*bs), y.value, y.rawType)
|
||||
else: assert false
|
||||
|
|
|
|||
|
|
@ -49,11 +49,11 @@ proc len*(s: SharedString): int = s.len
|
|||
|
||||
proc `[]`*(s: SharedString; i: Natural): char =
|
||||
if i < s.len: result = s.buffer.data[i+s.first]
|
||||
else: raise newException(IndexError, formatErrorIndexBound(i, s.len-1))
|
||||
else: raise newException(IndexDefect, formatErrorIndexBound(i, s.len-1))
|
||||
|
||||
proc `[]=`*(s: var SharedString; i: Natural; value: char) =
|
||||
if i < s.len: s.buffer.data[i+s.first] = value
|
||||
else: raise newException(IndexError, formatErrorIndexBound(i, s.len-1))
|
||||
else: raise newException(IndexDefect, formatErrorIndexBound(i, s.len-1))
|
||||
|
||||
proc `[]`*(s: SharedString; ab: HSlice[int, int]): SharedString =
|
||||
#incRef(src.buffer)
|
||||
|
|
|
|||
|
|
@ -240,7 +240,7 @@ proc getinfo[T](pattern: Regex, opt: cint): T =
|
|||
|
||||
if retcode < 0:
|
||||
# XXX Error message that doesn't expose implementation details
|
||||
raise newException(FieldError, "Invalid getinfo for $1, errno $2" % [$opt, $retcode])
|
||||
raise newException(FieldDefect, "Invalid getinfo for $1, errno $2" % [$opt, $retcode])
|
||||
|
||||
proc getNameToNumberTable(pattern: Regex): Table[string, int] =
|
||||
let entryCount = getinfo[cint](pattern, pcre.INFO_NAMECOUNT)
|
||||
|
|
@ -331,7 +331,7 @@ func contains*(pattern: Captures, i: int): bool =
|
|||
func `[]`*(pattern: CaptureBounds, i: int): HSlice[int, int] =
|
||||
let pattern = RegexMatch(pattern)
|
||||
if not (i in pattern.captureBounds):
|
||||
raise newException(IndexError, "Group '" & $i & "' was not captured")
|
||||
raise newException(IndexDefect, "Group '" & $i & "' was not captured")
|
||||
|
||||
let bounds = pattern.pcreMatchBounds[i + 1]
|
||||
int(bounds.a)..int(bounds.b-1)
|
||||
|
|
@ -517,7 +517,7 @@ proc matchImpl(str: string, pattern: Regex, start, endpos: int, flags: int): Opt
|
|||
of pcre.ERROR_NOMATCH:
|
||||
return none(RegexMatch)
|
||||
of pcre.ERROR_NULL:
|
||||
raise newException(AccessViolationError, "Expected non-null parameters")
|
||||
raise newException(AccessViolationDefect, "Expected non-null parameters")
|
||||
of pcre.ERROR_BADOPTION:
|
||||
raise RegexInternalError(msg : "Unknown pattern flag. Either a bug or " &
|
||||
"outdated PCRE.")
|
||||
|
|
@ -718,7 +718,7 @@ proc replace*(str: string, pattern: Regex,
|
|||
## - ``$#`` - first capture
|
||||
## - ``$0`` - full match
|
||||
##
|
||||
## If a given capture is missing, ``IndexError`` thrown for un-named captures
|
||||
## If a given capture is missing, ``IndexDefect`` thrown for un-named captures
|
||||
## and ``KeyError`` for named captures.
|
||||
replaceImpl(str, pattern, subproc(match))
|
||||
|
||||
|
|
|
|||
|
|
@ -75,14 +75,14 @@ template fillImpl[T](a: var openArray[T], first, last: int, value: T) =
|
|||
proc fill*[T](a: var openArray[T], first, last: Natural, value: T) =
|
||||
## Fills the slice ``a[first..last]`` with ``value``.
|
||||
##
|
||||
## If an invalid range is passed, it raises IndexError.
|
||||
## If an invalid range is passed, it raises IndexDefect.
|
||||
runnableExamples:
|
||||
var a: array[6, int]
|
||||
a.fill(1, 3, 9)
|
||||
assert a == [0, 9, 9, 9, 0, 0]
|
||||
a.fill(3, 5, 7)
|
||||
assert a == [0, 9, 9, 7, 7, 7]
|
||||
doAssertRaises(IndexError, a.fill(1, 7, 9))
|
||||
doAssertRaises(IndexDefect, a.fill(1, 7, 9))
|
||||
fillImpl(a, first, last, value)
|
||||
|
||||
proc fill*[T](a: var openArray[T], value: T) =
|
||||
|
|
@ -99,7 +99,7 @@ proc fill*[T](a: var openArray[T], value: T) =
|
|||
proc reverse*[T](a: var openArray[T], first, last: Natural) =
|
||||
## Reverses the slice ``a[first..last]``.
|
||||
##
|
||||
## If an invalid range is passed, it raises IndexError.
|
||||
## If an invalid range is passed, it raises IndexDefect.
|
||||
##
|
||||
## **See also:**
|
||||
## * `reversed proc<#reversed,openArray[T],Natural,int>`_ reverse a slice and returns a ``seq[T]``
|
||||
|
|
@ -110,7 +110,7 @@ proc reverse*[T](a: var openArray[T], first, last: Natural) =
|
|||
assert a == [1, 4, 3, 2, 5, 6]
|
||||
a.reverse(1, 3)
|
||||
assert a == [1, 2, 3, 4, 5, 6]
|
||||
doAssertRaises(IndexError, a.reverse(1, 7))
|
||||
doAssertRaises(IndexDefect, a.reverse(1, 7))
|
||||
var x = first
|
||||
var y = last
|
||||
while x < y:
|
||||
|
|
@ -135,7 +135,7 @@ proc reverse*[T](a: var openArray[T]) =
|
|||
proc reversed*[T](a: openArray[T], first: Natural, last: int): seq[T] =
|
||||
## Returns the reverse of the slice ``a[first..last]``.
|
||||
##
|
||||
## If an invalid range is passed, it raises IndexError.
|
||||
## If an invalid range is passed, it raises IndexDefect.
|
||||
##
|
||||
## **See also:**
|
||||
## * `reverse proc<#reverse,openArray[T],Natural,Natural>`_ reverse a slice
|
||||
|
|
@ -238,7 +238,7 @@ proc lowerBound*[T, K](a: openArray[T], key: K, cmp: proc(x: T, k: K): int {.
|
|||
## ``insert(thing, elm, lowerBound(thing, elm))``
|
||||
## the sequence will still be sorted.
|
||||
##
|
||||
## If an invalid range is passed, it raises IndexError.
|
||||
## If an invalid range is passed, it raises IndexDefect.
|
||||
##
|
||||
## The version uses ``cmp`` to compare the elements.
|
||||
## The expected return values are the same as that of ``system.cmp``.
|
||||
|
|
@ -286,7 +286,7 @@ proc upperBound*[T, K](a: openArray[T], key: K, cmp: proc(x: T, k: K): int {.
|
|||
## ``insert(thing, elm, upperBound(thing, elm))``
|
||||
## the sequence will still be sorted.
|
||||
##
|
||||
## If an invalid range is passed, it raises IndexError.
|
||||
## If an invalid range is passed, it raises IndexDefect.
|
||||
##
|
||||
## The version uses ``cmp`` to compare the elements. The expected
|
||||
## return values are the same as that of ``system.cmp``.
|
||||
|
|
@ -763,7 +763,7 @@ proc rotateLeft*[T](arg: var openArray[T]; slice: HSlice[int, int];
|
|||
##
|
||||
## Elements outside of ``slice`` will be left unchanged.
|
||||
## The time complexity is linear to ``slice.b - slice.a + 1``.
|
||||
## If an invalid range (``HSlice``) is passed, it raises IndexError.
|
||||
## If an invalid range (``HSlice``) is passed, it raises IndexDefect.
|
||||
##
|
||||
## ``slice``
|
||||
## The indices of the element range that should be rotated.
|
||||
|
|
@ -783,7 +783,7 @@ proc rotateLeft*[T](arg: var openArray[T]; slice: HSlice[int, int];
|
|||
assert a == [0, 3, 4, 1, 2, 5]
|
||||
a.rotateLeft(1 .. 4, -3)
|
||||
assert a == [0, 4, 1, 2, 3, 5]
|
||||
doAssertRaises(IndexError, a.rotateLeft(1 .. 7, 2))
|
||||
doAssertRaises(IndexDefect, a.rotateLeft(1 .. 7, 2))
|
||||
let sliceLen = slice.b + 1 - slice.a
|
||||
let distLeft = ((dist mod sliceLen) + sliceLen) mod sliceLen
|
||||
arg.rotateInternal(slice.a, slice.a+distLeft, slice.b + 1)
|
||||
|
|
@ -813,7 +813,7 @@ proc rotatedLeft*[T](arg: openArray[T]; slice: HSlice[int, int],
|
|||
## not modify the argument. It creates a new ``seq`` instead.
|
||||
##
|
||||
## Elements outside of ``slice`` will be left unchanged.
|
||||
## If an invalid range (``HSlice``) is passed, it raises IndexError.
|
||||
## If an invalid range (``HSlice``) is passed, it raises IndexDefect.
|
||||
##
|
||||
## ``slice``
|
||||
## The indices of the element range that should be rotated.
|
||||
|
|
|
|||
|
|
@ -31,7 +31,7 @@ template createCb(retFutureSym, iteratorNameSym,
|
|||
if not retFutUnown.finished:
|
||||
let msg = "Async procedure ($1) yielded `nil`, are you await'ing a " &
|
||||
"`nil` Future?"
|
||||
raise newException(AssertionError, msg % strName)
|
||||
raise newException(AssertionDefect, msg % strName)
|
||||
else:
|
||||
{.gcsafe.}:
|
||||
{.push hint[ConvFromXtoItselfNotNeeded]: off.}
|
||||
|
|
@ -260,7 +260,7 @@ proc asyncSingleProc(prc: NimNode): NimNode {.compileTime.} =
|
|||
template await(f: typed): untyped =
|
||||
static:
|
||||
error "await expects Future[T], got " & $typeof(f)
|
||||
|
||||
|
||||
template await[T](f: Future[T]): auto =
|
||||
var internalTmpFuture: FutureBase = f
|
||||
yield internalTmpFuture
|
||||
|
|
|
|||
|
|
@ -12,7 +12,7 @@
|
|||
##
|
||||
## None of the procs that get an individual value from the deque can be used
|
||||
## on an empty deque.
|
||||
## If compiled with `boundChecks` option, those procs will raise an `IndexError`
|
||||
## If compiled with `boundChecks` option, those procs will raise an `IndexDefect`
|
||||
## on such access. This should not be relied upon, as `-d:release` will
|
||||
## disable those checks and may return garbage or crash the program.
|
||||
##
|
||||
|
|
@ -24,7 +24,7 @@
|
|||
##
|
||||
## var a = initDeque[int]()
|
||||
##
|
||||
## doAssertRaises(IndexError, echo a[0])
|
||||
## doAssertRaises(IndexDefect, echo a[0])
|
||||
##
|
||||
## for i in 1 .. 5:
|
||||
## a.addLast(10*i)
|
||||
|
|
@ -70,7 +70,7 @@ template initImpl(result: typed, initialSize: int) =
|
|||
assert isPowerOfTwo(initialSize)
|
||||
result.mask = initialSize-1
|
||||
newSeq(result.data, initialSize)
|
||||
|
||||
|
||||
template checkIfInitialized(deq: typed) =
|
||||
when compiles(defaultInitialSize):
|
||||
if deq.mask == 0:
|
||||
|
|
@ -97,16 +97,16 @@ template emptyCheck(deq) =
|
|||
# Bounds check for the regular deque access.
|
||||
when compileOption("boundChecks"):
|
||||
if unlikely(deq.count < 1):
|
||||
raise newException(IndexError, "Empty deque.")
|
||||
raise newException(IndexDefect, "Empty deque.")
|
||||
|
||||
template xBoundsCheck(deq, i) =
|
||||
# Bounds check for the array like accesses.
|
||||
when compileOption("boundChecks"): # d:release should disable this.
|
||||
if unlikely(i >= deq.count): # x < deq.low is taken care by the Natural parameter
|
||||
raise newException(IndexError,
|
||||
raise newException(IndexDefect,
|
||||
"Out of bounds: " & $i & " > " & $(deq.count - 1))
|
||||
if unlikely(i < 0): # when used with BackwardsIndex
|
||||
raise newException(IndexError,
|
||||
raise newException(IndexDefect,
|
||||
"Out of bounds: " & $i & " < 0")
|
||||
|
||||
proc `[]`*[T](deq: Deque[T], i: Natural): T {.inline.} =
|
||||
|
|
@ -117,7 +117,7 @@ proc `[]`*[T](deq: Deque[T], i: Natural): T {.inline.} =
|
|||
a.addLast(10*i)
|
||||
assert a[0] == 10
|
||||
assert a[3] == 40
|
||||
doAssertRaises(IndexError, echo a[8])
|
||||
doAssertRaises(IndexDefect, echo a[8])
|
||||
|
||||
xBoundsCheck(deq, i)
|
||||
return deq.data[(deq.head + i) and deq.mask]
|
||||
|
|
@ -131,7 +131,7 @@ proc `[]`*[T](deq: var Deque[T], i: Natural): var T {.inline.} =
|
|||
a.addLast(10*i)
|
||||
assert a[0] == 10
|
||||
assert a[3] == 40
|
||||
doAssertRaises(IndexError, echo a[8])
|
||||
doAssertRaises(IndexDefect, echo a[8])
|
||||
|
||||
xBoundsCheck(deq, i)
|
||||
return deq.data[(deq.head + i) and deq.mask]
|
||||
|
|
@ -160,7 +160,7 @@ proc `[]`*[T](deq: Deque[T], i: BackwardsIndex): T {.inline.} =
|
|||
a.addLast(10*i)
|
||||
assert a[^1] == 50
|
||||
assert a[^4] == 20
|
||||
doAssertRaises(IndexError, echo a[^9])
|
||||
doAssertRaises(IndexDefect, echo a[^9])
|
||||
|
||||
xBoundsCheck(deq, deq.len - int(i))
|
||||
return deq[deq.len - int(i)]
|
||||
|
|
@ -175,7 +175,7 @@ proc `[]`*[T](deq: var Deque[T], i: BackwardsIndex): var T {.inline.} =
|
|||
a.addLast(10*i)
|
||||
assert a[^1] == 50
|
||||
assert a[^4] == 20
|
||||
doAssertRaises(IndexError, echo a[^9])
|
||||
doAssertRaises(IndexDefect, echo a[^9])
|
||||
|
||||
xBoundsCheck(deq, deq.len - int(i))
|
||||
return deq[deq.len - int(i)]
|
||||
|
|
@ -569,14 +569,14 @@ when isMainModule:
|
|||
try:
|
||||
echo deq[99]
|
||||
assert false
|
||||
except IndexError:
|
||||
except IndexDefect:
|
||||
discard
|
||||
|
||||
try:
|
||||
assert deq.len == 4
|
||||
for i in 0 ..< 5: deq.popFirst()
|
||||
assert false
|
||||
except IndexError:
|
||||
except IndexDefect:
|
||||
discard
|
||||
|
||||
# grabs some types of resize error.
|
||||
|
|
|
|||
|
|
@ -26,11 +26,11 @@
|
|||
##
|
||||
## .. code-block:: Nim
|
||||
## import asyncdispatch, httpclient
|
||||
##
|
||||
##
|
||||
## proc asyncProc(): Future[string] {.async.} =
|
||||
## var client = newAsyncHttpClient()
|
||||
## return await client.getContent("http://example.com")
|
||||
##
|
||||
##
|
||||
## echo waitFor asyncProc()
|
||||
##
|
||||
## The functionality implemented by ``HttpClient`` and ``AsyncHttpClient``
|
||||
|
|
@ -225,7 +225,7 @@ type
|
|||
bodyStream*: FutureStream[string]
|
||||
|
||||
proc code*(response: Response | AsyncResponse): HttpCode
|
||||
{.raises: [ValueError, OverflowError].} =
|
||||
{.raises: [ValueError, OverflowDefect].} =
|
||||
## Retrieves the specified response's ``HttpCode``.
|
||||
##
|
||||
## Raises a ``ValueError`` if the response's ``status`` does not have a
|
||||
|
|
|
|||
|
|
@ -1300,18 +1300,18 @@ when isMainModule:
|
|||
when compileOption("boundChecks"):
|
||||
try:
|
||||
let a = testJson["a"][9]
|
||||
doAssert(false, "IndexError not thrown")
|
||||
except IndexError:
|
||||
doAssert(false, "IndexDefect not thrown")
|
||||
except IndexDefect:
|
||||
discard
|
||||
try:
|
||||
let a = testJson["a"][-1]
|
||||
doAssert(false, "IndexError not thrown")
|
||||
except IndexError:
|
||||
doAssert(false, "IndexDefect not thrown")
|
||||
except IndexDefect:
|
||||
discard
|
||||
try:
|
||||
doAssert(testJson["a"][0].num == 1, "Index doesn't correspond to its value")
|
||||
except:
|
||||
doAssert(false, "IndexError thrown for valid index")
|
||||
doAssert(false, "IndexDefect thrown for valid index")
|
||||
|
||||
doAssert(testJson{"b"}.getStr() == "asd", "Couldn't fetch a singly nested key with {}")
|
||||
doAssert(isNil(testJson{"nonexistent"}), "Non-existent keys should return nil")
|
||||
|
|
@ -1378,7 +1378,7 @@ when isMainModule:
|
|||
try:
|
||||
discard parsed["key2"][12123]
|
||||
doAssert(false)
|
||||
except IndexError: doAssert(true)
|
||||
except IndexDefect: doAssert(true)
|
||||
|
||||
var parsed2 = parseFile("tests/testdata/jsontest2.json")
|
||||
doAssert(parsed2{"repository", "description"}.str ==
|
||||
|
|
|
|||
|
|
@ -1205,7 +1205,7 @@ when isMainModule:
|
|||
block: # fac() tests
|
||||
try:
|
||||
discard fac(-1)
|
||||
except AssertionError:
|
||||
except AssertionDefect:
|
||||
discard
|
||||
|
||||
doAssert fac(0) == 1
|
||||
|
|
|
|||
|
|
@ -457,7 +457,7 @@ proc fromSockAddrAux(sa: ptr Sockaddr_storage, sl: SockLen,
|
|||
proc fromSockAddr*(sa: Sockaddr_storage | SockAddr | Sockaddr_in | Sockaddr_in6,
|
||||
sl: SockLen, address: var IpAddress, port: var Port) {.inline.} =
|
||||
## Converts `SockAddr` and `SockLen` to `IpAddress` and `Port`. Raises
|
||||
## `ObjectConversionError` in case of invalid `sa` and `sl` arguments.
|
||||
## `ObjectConversionDefect` in case of invalid `sa` and `sl` arguments.
|
||||
fromSockAddrAux(cast[ptr Sockaddr_storage](unsafeAddr sa), sl, address, port)
|
||||
|
||||
when defineSsl:
|
||||
|
|
@ -488,7 +488,7 @@ when defineSsl:
|
|||
proc getExtraData*(ctx: SslContext, index: int): RootRef =
|
||||
## Retrieves arbitrary data stored inside SslContext.
|
||||
if index notin ctx.referencedData:
|
||||
raise newException(IndexError, "No data with that index.")
|
||||
raise newException(IndexDefect, "No data with that index.")
|
||||
let res = ctx.context.SSL_CTX_get_ex_data(index.cint)
|
||||
if cast[int](res) == 0:
|
||||
raiseSSLError()
|
||||
|
|
|
|||
|
|
@ -74,8 +74,8 @@ type
|
|||
val: T
|
||||
has: bool
|
||||
|
||||
UnpackError* = object of Defect
|
||||
|
||||
UnpackDefect* = object of Defect
|
||||
UnpackError* {.deprecated: "See corresponding Defect".} = UnpackDefect
|
||||
|
||||
proc option*[T](val: T): Option[T] =
|
||||
## Can be used to convert a pointer type (`ptr` or `ref` or `proc`) to an option type.
|
||||
|
|
@ -486,7 +486,7 @@ when isMainModule:
|
|||
|
||||
let tmp = option(intref)
|
||||
check(sizeof(tmp) == sizeof(ptr int))
|
||||
|
||||
|
||||
var prc = proc (x: int): int = x + 1
|
||||
check(option(prc).isSome)
|
||||
prc = nil
|
||||
|
|
|
|||
|
|
@ -2678,7 +2678,7 @@ when defined(nimdoc):
|
|||
proc paramStr*(i: int): TaintedString {.tags: [ReadIOEffect].} =
|
||||
## Returns the `i`-th `command line argument`:idx: given to the application.
|
||||
##
|
||||
## `i` should be in the range `1..paramCount()`, the `IndexError`
|
||||
## `i` should be in the range `1..paramCount()`, the `IndexDefect`
|
||||
## exception will be raised for invalid values. Instead of iterating over
|
||||
## `paramCount() <#paramCount>`_ with this proc you can call the
|
||||
## convenience `commandLineParams() <#commandLineParams>`_.
|
||||
|
|
@ -2754,7 +2754,7 @@ elif defined(windows):
|
|||
ownArgv = parseCmdLine($getCommandLine())
|
||||
ownParsedArgv = true
|
||||
if i < ownArgv.len and i >= 0: return TaintedString(ownArgv[i])
|
||||
raise newException(IndexError, formatErrorIndexBound(i, ownArgv.len-1))
|
||||
raise newException(IndexDefect, formatErrorIndexBound(i, ownArgv.len-1))
|
||||
|
||||
elif defined(genode):
|
||||
proc paramStr*(i: int): TaintedString =
|
||||
|
|
@ -2773,7 +2773,7 @@ elif not defined(createNimRtl) and
|
|||
proc paramStr*(i: int): TaintedString {.tags: [ReadIOEffect].} =
|
||||
# Docstring in nimdoc block.
|
||||
if i < cmdCount and i >= 0: return TaintedString($cmdLine[i])
|
||||
raise newException(IndexError, formatErrorIndexBound(i, cmdCount-1))
|
||||
raise newException(IndexDefect, formatErrorIndexBound(i, cmdCount-1))
|
||||
|
||||
proc paramCount*(): int {.tags: [ReadIOEffect].} =
|
||||
# Docstring in nimdoc block.
|
||||
|
|
|
|||
|
|
@ -393,7 +393,7 @@ proc captureBetween*(s: string, first: char, second = '\0', start = 0): string =
|
|||
result = ""
|
||||
discard s.parseUntil(result, if second == '\0': first else: second, i)
|
||||
|
||||
proc integerOutOfRangeError() {.noinline.} =
|
||||
proc integerOutOfRangeDefect() {.noinline.} =
|
||||
raise newException(ValueError, "Parsed integer outside of valid range")
|
||||
|
||||
# See #6752
|
||||
|
|
@ -416,11 +416,11 @@ proc rawParseInt(s: string, b: var BiggestInt, start = 0): int =
|
|||
if b >= (low(BiggestInt) + c) div 10:
|
||||
b = b * 10 - c
|
||||
else:
|
||||
integerOutOfRangeError()
|
||||
integerOutOfRangeDefect()
|
||||
inc(i)
|
||||
while i < s.len and s[i] == '_': inc(i) # underscores are allowed and ignored
|
||||
if sign == -1 and b == low(BiggestInt):
|
||||
integerOutOfRangeError()
|
||||
integerOutOfRangeDefect()
|
||||
else:
|
||||
b = b * sign
|
||||
result = i - start
|
||||
|
|
@ -459,7 +459,7 @@ proc parseInt*(s: string, number: var int, start = 0): int {.
|
|||
result = parseBiggestInt(s, res, start)
|
||||
when sizeof(int) <= 4:
|
||||
if res < low(int) or res > high(int):
|
||||
integerOutOfRangeError()
|
||||
integerOutOfRangeDefect()
|
||||
if result != 0:
|
||||
number = int(res)
|
||||
|
||||
|
|
@ -493,7 +493,7 @@ proc rawParseUInt(s: string, b: var BiggestUInt, start = 0): int =
|
|||
prev = 0.BiggestUInt
|
||||
i = start
|
||||
if i < s.len - 1 and s[i] == '-' and s[i + 1] in {'0'..'9'}:
|
||||
integerOutOfRangeError()
|
||||
integerOutOfRangeDefect()
|
||||
if i < s.len and s[i] == '+': inc(i) # Allow
|
||||
if i < s.len and s[i] in {'0'..'9'}:
|
||||
b = 0
|
||||
|
|
@ -501,7 +501,7 @@ proc rawParseUInt(s: string, b: var BiggestUInt, start = 0): int =
|
|||
prev = res
|
||||
res = res * 10 + (ord(s[i]) - ord('0')).BiggestUInt
|
||||
if prev > res:
|
||||
integerOutOfRangeError()
|
||||
integerOutOfRangeDefect()
|
||||
inc(i)
|
||||
while i < s.len and s[i] == '_': inc(i) # underscores are allowed and ignored
|
||||
b = res
|
||||
|
|
@ -540,7 +540,7 @@ proc parseUInt*(s: string, number: var uint, start = 0): int {.
|
|||
result = parseBiggestUInt(s, res, start)
|
||||
when sizeof(BiggestUInt) > sizeof(uint) and sizeof(uint) <= 4:
|
||||
if res > 0xFFFF_FFFF'u64:
|
||||
integerOutOfRangeError()
|
||||
integerOutOfRangeDefect()
|
||||
if result != 0:
|
||||
number = uint(res)
|
||||
|
||||
|
|
|
|||
|
|
@ -676,13 +676,13 @@ when isMainModule:
|
|||
try:
|
||||
discard rand(-1)
|
||||
doAssert false
|
||||
except RangeError:
|
||||
except RangeDefect:
|
||||
discard
|
||||
|
||||
try:
|
||||
discard rand(-1.0)
|
||||
doAssert false
|
||||
except RangeError:
|
||||
except RangeDefect:
|
||||
discard
|
||||
|
||||
|
||||
|
|
|
|||
|
|
@ -93,7 +93,7 @@ proc reduce*[T: SomeInteger](x: var Rational[T]) =
|
|||
x.num = -x.num div common
|
||||
x.den = -x.den div common
|
||||
else:
|
||||
raise newException(DivByZeroError, "division by zero")
|
||||
raise newException(DivByZeroDefect, "division by zero")
|
||||
|
||||
proc `+` *[T](x, y: Rational[T]): Rational[T] =
|
||||
## Add two rational numbers.
|
||||
|
|
@ -194,7 +194,7 @@ proc reciprocal*[T](x: Rational[T]): Rational[T] =
|
|||
result.num = -x.den
|
||||
result.den = -x.num
|
||||
else:
|
||||
raise newException(DivByZeroError, "division by zero")
|
||||
raise newException(DivByZeroDefect, "division by zero")
|
||||
|
||||
proc `/`*[T](x, y: Rational[T]): Rational[T] =
|
||||
## Divide rationals `x` by `y`.
|
||||
|
|
|
|||
|
|
@ -8,17 +8,17 @@
|
|||
#
|
||||
|
||||
## This modules registers a signal handler that turns access violations /
|
||||
## segfaults into a ``NilAccessError`` exception. To be able to catch
|
||||
## a NilAccessError all you have to do is to import this module.
|
||||
## segfaults into a ``NilAccessDefect`` exception. To be able to catch
|
||||
## a NilAccessDefect all you have to do is to import this module.
|
||||
##
|
||||
## Tested on these OSes: Linux, Windows, OSX
|
||||
|
||||
{.used.}
|
||||
|
||||
# do allocate memory upfront:
|
||||
var se: ref NilAccessError
|
||||
var se: ref NilAccessDefect
|
||||
new(se)
|
||||
se.name = "NilAccessError"
|
||||
se.name = "NilAccessDefect"
|
||||
se.msg = "Could not access value because it is nil."
|
||||
|
||||
when defined(windows):
|
||||
|
|
|
|||
|
|
@ -88,7 +88,7 @@
|
|||
##
|
||||
## test "out of bounds error is thrown on bad access":
|
||||
## let v = @[1, 2, 3] # you can do initialization here
|
||||
## expect(IndexError):
|
||||
## expect(IndexDefect):
|
||||
## discard v[4]
|
||||
##
|
||||
## echo "suite teardown: run once after the tests"
|
||||
|
|
@ -190,7 +190,7 @@ proc delOutputFormatter*(formatter: OutputFormatter) =
|
|||
|
||||
proc resetOutputFormatters* {.since: (1, 1).} =
|
||||
formatters = @[]
|
||||
|
||||
|
||||
proc newConsoleOutputFormatter*(outputLevel: OutputLevel = OutputLevel.PRINT_ALL,
|
||||
colorOutput = true): <//>ConsoleOutputFormatter =
|
||||
ConsoleOutputFormatter(
|
||||
|
|
@ -717,7 +717,7 @@ macro expect*(exceptions: varargs[typed], body: untyped): untyped =
|
|||
## of 3: raise newException(IOError, "I can't do that Dave.")
|
||||
## else: assert 2 + 2 == 5
|
||||
##
|
||||
## expect IOError, OSError, ValueError, AssertionError:
|
||||
## expect IOError, OSError, ValueError, AssertionDefect:
|
||||
## defectiveRobot()
|
||||
let exp = callsite()
|
||||
template expectBody(errorTypes, lineInfoLit, body): NimNode {.dirty.} =
|
||||
|
|
|
|||
|
|
@ -64,7 +64,7 @@ template `[]`*[I](a: Wrapnil, i: I): untyped =
|
|||
## See top-level example.
|
||||
let a1 = a # to avoid double evaluations
|
||||
if a1.validImpl:
|
||||
# correctly will raise IndexError if a is valid but wraps an empty container
|
||||
# correctly will raise IndexDefect if a is valid but wraps an empty container
|
||||
wrapnil(a1.valueImpl[i])
|
||||
else:
|
||||
default(Wrapnil[type(a1.valueImpl[i])])
|
||||
|
|
|
|||
|
|
@ -868,8 +868,8 @@ proc `of`*[T, S](x: T, y: S): bool {.magic: "Of", noSideEffect.}
|
|||
## Checks if `x` has a type of `y`.
|
||||
##
|
||||
## .. code-block:: Nim
|
||||
## assert(FloatingPointError of Exception)
|
||||
## assert(DivByZeroError of Exception)
|
||||
## assert(FloatingPointDefect of Exception)
|
||||
## assert(DivByZeroDefect of Exception)
|
||||
|
||||
proc cmp*[T](x, y: T): int {.procvar.} =
|
||||
## Generic compare proc.
|
||||
|
|
@ -1673,8 +1673,8 @@ proc instantiationInfo*(index = -1, fullPaths = false): tuple[
|
|||
## result = a[pos]
|
||||
##
|
||||
## when isMainModule:
|
||||
## testException(IndexError, tester(30))
|
||||
## testException(IndexError, tester(1))
|
||||
## testException(IndexDefect, tester(30))
|
||||
## testException(IndexDefect, tester(1))
|
||||
## # --> Test failure at example.nim:20 with 'tester(1)'
|
||||
|
||||
proc compiles*(x: untyped): bool {.magic: "Compiles", noSideEffect, compileTime.} =
|
||||
|
|
@ -2493,7 +2493,7 @@ proc `[]=`*[Idx, T, U, V](a: var array[Idx, T], x: HSlice[U, V], b: openArray[T]
|
|||
if L == b.len:
|
||||
for i in 0..<L: a[Idx(i + xa)] = b[i]
|
||||
else:
|
||||
sysFatal(RangeError, "different lengths for slice assignment")
|
||||
sysFatal(RangeDefect, "different lengths for slice assignment")
|
||||
|
||||
proc `[]`*[T, U, V](s: openArray[T], x: HSlice[U, V]): seq[T] =
|
||||
## Slice operation for sequences.
|
||||
|
|
@ -2655,7 +2655,7 @@ when compileOption("rangechecks"):
|
|||
## Helper for performing user-defined range checks.
|
||||
## Such checks will be performed only when the ``rangechecks``
|
||||
## compile-time option is enabled.
|
||||
if not cond: sysFatal(RangeError, "range check failed")
|
||||
if not cond: sysFatal(RangeDefect, "range check failed")
|
||||
else:
|
||||
template rangeCheck*(cond) = discard
|
||||
|
||||
|
|
|
|||
|
|
@ -12,10 +12,10 @@
|
|||
|
||||
proc raiseOverflow {.compilerproc, noinline.} =
|
||||
# a single proc to reduce code size to a minimum
|
||||
sysFatal(OverflowError, "over- or underflow")
|
||||
sysFatal(OverflowDefect, "over- or underflow")
|
||||
|
||||
proc raiseDivByZero {.compilerproc, noinline.} =
|
||||
sysFatal(DivByZeroError, "division by zero")
|
||||
sysFatal(DivByZeroDefect, "division by zero")
|
||||
|
||||
when defined(builtinOverflow):
|
||||
# Builtin compiler functions for improved performance
|
||||
|
|
@ -410,16 +410,16 @@ when not declared(mulInt):
|
|||
# written in other languages.
|
||||
|
||||
proc raiseFloatInvalidOp {.compilerproc, noinline.} =
|
||||
sysFatal(FloatInvalidOpError, "FPU operation caused a NaN result")
|
||||
sysFatal(FloatInvalidOpDefect, "FPU operation caused a NaN result")
|
||||
|
||||
proc nanCheck(x: float64) {.compilerproc, inline.} =
|
||||
if x != x: raiseFloatInvalidOp()
|
||||
|
||||
proc raiseFloatOverflow(x: float64) {.compilerproc, noinline.} =
|
||||
if x > 0.0:
|
||||
sysFatal(FloatOverflowError, "FPU operation caused an overflow")
|
||||
sysFatal(FloatOverflowDefect, "FPU operation caused an overflow")
|
||||
else:
|
||||
sysFatal(FloatUnderflowError, "FPU operations caused an underflow")
|
||||
sysFatal(FloatUnderflowDefect, "FPU operations caused an underflow")
|
||||
|
||||
proc infCheck(x: float64) {.compilerproc, inline.} =
|
||||
if x != 0.0 and x*0.5 == x: raiseFloatOverflow(x)
|
||||
|
|
|
|||
|
|
@ -2,7 +2,7 @@ proc succ*[T: Ordinal](x: T, y = 1): T {.magic: "Succ", noSideEffect.}
|
|||
## Returns the ``y``-th successor (default: 1) of the value ``x``.
|
||||
## ``T`` has to be an `ordinal type <#Ordinal>`_.
|
||||
##
|
||||
## If such a value does not exist, ``OverflowError`` is raised
|
||||
## If such a value does not exist, ``OverflowDefect`` is raised
|
||||
## or a compile time error occurs.
|
||||
##
|
||||
## .. code-block:: Nim
|
||||
|
|
@ -14,7 +14,7 @@ proc pred*[T: Ordinal](x: T, y = 1): T {.magic: "Pred", noSideEffect.}
|
|||
## Returns the ``y``-th predecessor (default: 1) of the value ``x``.
|
||||
## ``T`` has to be an `ordinal type <#Ordinal>`_.
|
||||
##
|
||||
## If such a value does not exist, ``OverflowError`` is raised
|
||||
## If such a value does not exist, ``OverflowDefect`` is raised
|
||||
## or a compile time error occurs.
|
||||
##
|
||||
## .. code-block:: Nim
|
||||
|
|
@ -25,7 +25,7 @@ proc pred*[T: Ordinal](x: T, y = 1): T {.magic: "Pred", noSideEffect.}
|
|||
proc inc*[T: Ordinal](x: var T, y = 1) {.magic: "Inc", noSideEffect.}
|
||||
## Increments the ordinal ``x`` by ``y``.
|
||||
##
|
||||
## If such a value does not exist, ``OverflowError`` is raised or a compile
|
||||
## If such a value does not exist, ``OverflowDefect`` is raised or a compile
|
||||
## time error occurs. This is a short notation for: ``x = succ(x, y)``.
|
||||
##
|
||||
## .. code-block:: Nim
|
||||
|
|
@ -36,7 +36,7 @@ proc inc*[T: Ordinal](x: var T, y = 1) {.magic: "Inc", noSideEffect.}
|
|||
proc dec*[T: Ordinal](x: var T, y = 1) {.magic: "Dec", noSideEffect.}
|
||||
## Decrements the ordinal ``x`` by ``y``.
|
||||
##
|
||||
## If such a value does not exist, ``OverflowError`` is raised or a compile
|
||||
## If such a value does not exist, ``OverflowDefect`` is raised or a compile
|
||||
## time error occurs. This is a short notation for: ``x = pred(x, y)``.
|
||||
##
|
||||
## .. code-block:: Nim
|
||||
|
|
|
|||
|
|
@ -19,10 +19,10 @@ when not defined(nimHasSinkInference):
|
|||
{.pragma: nosinks.}
|
||||
|
||||
proc raiseAssert*(msg: string) {.noinline, noreturn, nosinks.} =
|
||||
sysFatal(AssertionError, msg)
|
||||
sysFatal(AssertionDefect, msg)
|
||||
|
||||
proc failedAssertImpl*(msg: string) {.raises: [], tags: [].} =
|
||||
# trick the compiler to not list ``AssertionError`` when called
|
||||
# trick the compiler to not list ``AssertionDefect`` when called
|
||||
# by ``assert``.
|
||||
type Hide = proc (msg: string) {.noinline, raises: [], noSideEffect,
|
||||
tags: [].}
|
||||
|
|
@ -40,9 +40,9 @@ template assertImpl(cond: bool, msg: string, expr: string, enabled: static[bool]
|
|||
failedAssertImpl(ploc & " `" & expr & "` " & msg)
|
||||
|
||||
template assert*(cond: untyped, msg = "") =
|
||||
## Raises ``AssertionError`` with `msg` if `cond` is false. Note
|
||||
## that ``AssertionError`` is hidden from the effect system, so it doesn't
|
||||
## produce ``{.raises: [AssertionError].}``. This exception is only supposed
|
||||
## Raises ``AssertionDefect`` with `msg` if `cond` is false. Note
|
||||
## that ``AssertionDefect`` is hidden from the effect system, so it doesn't
|
||||
## produce ``{.raises: [AssertionDefect].}``. This exception is only supposed
|
||||
## to be caught by unit testing frameworks.
|
||||
##
|
||||
## The compiler may not generate any code at all for ``assert`` if it is
|
||||
|
|
@ -80,7 +80,7 @@ template onFailedAssert*(msg, code: untyped): untyped {.dirty.} =
|
|||
code
|
||||
|
||||
template doAssertRaises*(exception: typedesc, code: untyped) =
|
||||
## Raises ``AssertionError`` if specified ``code`` does not raise the
|
||||
## Raises ``AssertionDefect`` if specified ``code`` does not raise the
|
||||
## specified exception. Example:
|
||||
##
|
||||
## .. code-block:: nim
|
||||
|
|
|
|||
|
|
@ -233,10 +233,10 @@ proc FieldDiscriminantCheck(oldDiscVal, newDiscVal: int,
|
|||
let newBranch = selectBranch(newDiscVal, L, a)
|
||||
when defined(nimOldCaseObjects):
|
||||
if newBranch != oldBranch and oldDiscVal != 0:
|
||||
sysFatal(FieldError, "assignment to discriminant changes object branch")
|
||||
sysFatal(FieldDefect, "assignment to discriminant changes object branch")
|
||||
else:
|
||||
if newBranch != oldBranch:
|
||||
if oldDiscVal != 0:
|
||||
sysFatal(FieldError, "assignment to discriminant changes object branch")
|
||||
sysFatal(FieldDefect, "assignment to discriminant changes object branch")
|
||||
else:
|
||||
sysFatal(FieldError, "assignment to discriminant changes object branch; compile with -d:nimOldCaseObjects for a transition period")
|
||||
sysFatal(FieldDefect, "assignment to discriminant changes object branch; compile with -d:nimOldCaseObjects for a transition period")
|
||||
|
|
|
|||
|
|
@ -347,7 +347,7 @@ template lockChannel(q, action): untyped =
|
|||
|
||||
proc sendImpl(q: PRawChannel, typ: PNimType, msg: pointer, noBlock: bool): bool =
|
||||
if q.mask == ChannelDeadMask:
|
||||
sysFatal(DeadThreadError, "cannot send message; thread died")
|
||||
sysFatal(DeadThreadDefect, "cannot send message; thread died")
|
||||
acquireSys(q.lock)
|
||||
if q.maxItems > 0:
|
||||
# Wait until count is less than maxItems
|
||||
|
|
|
|||
|
|
@ -12,34 +12,34 @@ include system/indexerrors
|
|||
|
||||
proc raiseRangeError(val: BiggestInt) {.compilerproc, noinline.} =
|
||||
when hostOS == "standalone":
|
||||
sysFatal(RangeError, "value out of range")
|
||||
sysFatal(RangeDefect, "value out of range")
|
||||
else:
|
||||
sysFatal(RangeError, "value out of range: ", $val)
|
||||
sysFatal(RangeDefect, "value out of range: ", $val)
|
||||
|
||||
proc raiseIndexError3(i, a, b: int) {.compilerproc, noinline.} =
|
||||
sysFatal(IndexError, formatErrorIndexBound(i, a, b))
|
||||
sysFatal(IndexDefect, formatErrorIndexBound(i, a, b))
|
||||
|
||||
proc raiseIndexError2(i, n: int) {.compilerproc, noinline.} =
|
||||
sysFatal(IndexError, formatErrorIndexBound(i, n))
|
||||
sysFatal(IndexDefect, formatErrorIndexBound(i, n))
|
||||
|
||||
proc raiseIndexError() {.compilerproc, noinline.} =
|
||||
sysFatal(IndexError, "index out of bounds")
|
||||
sysFatal(IndexDefect, "index out of bounds")
|
||||
|
||||
proc raiseFieldError(f: string) {.compilerproc, noinline.} =
|
||||
sysFatal(FieldError, f)
|
||||
sysFatal(FieldDefect, f)
|
||||
|
||||
proc raiseRangeErrorI(i, a, b: BiggestInt) {.compilerproc, noinline.} =
|
||||
sysFatal(RangeError, "value out of range: " & $i & " notin " & $a & " .. " & $b)
|
||||
sysFatal(RangeDefect, "value out of range: " & $i & " notin " & $a & " .. " & $b)
|
||||
|
||||
proc raiseRangeErrorF(i, a, b: float) {.compilerproc, noinline.} =
|
||||
sysFatal(RangeError, "value out of range: " & $i & " notin " & $a & " .. " & $b)
|
||||
sysFatal(RangeDefect, "value out of range: " & $i & " notin " & $a & " .. " & $b)
|
||||
|
||||
proc raiseRangeErrorU(i, a, b: uint64) {.compilerproc, noinline.} =
|
||||
# todo: better error reporting
|
||||
sysFatal(RangeError, "value out of range")
|
||||
sysFatal(RangeDefect, "value out of range")
|
||||
|
||||
proc raiseObjectConversionError() {.compilerproc, noinline.} =
|
||||
sysFatal(ObjectConversionError, "invalid object conversion")
|
||||
sysFatal(ObjectConversionDefect, "invalid object conversion")
|
||||
|
||||
proc chckIndx(i, a, b: int): int =
|
||||
if i >= a and i <= b:
|
||||
|
|
@ -63,24 +63,24 @@ proc chckRangeU(i, a, b: uint64): uint64 {.compilerproc.} =
|
|||
if i >= a and i <= b:
|
||||
return i
|
||||
else:
|
||||
sysFatal(RangeError, "value out of range")
|
||||
sysFatal(RangeDefect, "value out of range")
|
||||
|
||||
proc chckRangeF(x, a, b: float): float =
|
||||
if x >= a and x <= b:
|
||||
return x
|
||||
else:
|
||||
when hostOS == "standalone":
|
||||
sysFatal(RangeError, "value out of range")
|
||||
sysFatal(RangeDefect, "value out of range")
|
||||
else:
|
||||
sysFatal(RangeError, "value out of range: ", $x)
|
||||
sysFatal(RangeDefect, "value out of range: ", $x)
|
||||
|
||||
proc chckNil(p: pointer) =
|
||||
if p == nil:
|
||||
sysFatal(NilAccessError, "attempt to write to a nil address")
|
||||
sysFatal(NilAccessDefect, "attempt to write to a nil address")
|
||||
|
||||
proc chckNilDisp(p: pointer) {.compilerproc.} =
|
||||
if p == nil:
|
||||
sysFatal(NilAccessError, "cannot dispatch; dispatcher is nil")
|
||||
sysFatal(NilAccessDefect, "cannot dispatch; dispatcher is nil")
|
||||
|
||||
when not defined(nimV2):
|
||||
|
||||
|
|
@ -90,12 +90,12 @@ when not defined(nimV2):
|
|||
if x == subclass: return # optimized fast path
|
||||
while x != subclass:
|
||||
if x == nil:
|
||||
sysFatal(ObjectConversionError, "invalid object conversion")
|
||||
sysFatal(ObjectConversionDefect, "invalid object conversion")
|
||||
x = x.base
|
||||
|
||||
proc chckObjAsgn(a, b: PNimType) {.compilerproc, inline.} =
|
||||
if a != b:
|
||||
sysFatal(ObjectAssignmentError, "invalid object assignment")
|
||||
sysFatal(ObjectAssignmentDefect, "invalid object assignment")
|
||||
|
||||
type ObjCheckCache = array[0..1, PNimType]
|
||||
|
||||
|
|
@ -130,4 +130,4 @@ when not defined(nimV2):
|
|||
|
||||
when defined(nimV2):
|
||||
proc raiseObjectCaseTransition() {.compilerproc.} =
|
||||
sysFatal(FieldError, "assignment to discriminant changes object branch")
|
||||
sysFatal(FieldDefect, "assignment to discriminant changes object branch")
|
||||
|
|
|
|||
|
|
@ -32,10 +32,10 @@ const
|
|||
proc quitOrDebug() {.noreturn, importc: "abort", header: "<stdlib.h>", nodecl.}
|
||||
|
||||
proc raiseException(e: ref Exception, ename: cstring) {.compilerRtl.} =
|
||||
sysFatal(ReraiseError, "exception handling is not available")
|
||||
sysFatal(ReraiseDefect, "exception handling is not available")
|
||||
|
||||
proc reraiseException() {.compilerRtl.} =
|
||||
sysFatal(ReraiseError, "no exception to reraise")
|
||||
sysFatal(ReraiseDefect, "no exception to reraise")
|
||||
|
||||
proc writeStackTrace() = discard
|
||||
|
||||
|
|
@ -43,4 +43,4 @@ proc unsetControlCHook() = discard
|
|||
proc setControlCHook(hook: proc () {.noconv.}) = discard
|
||||
|
||||
proc closureIterSetupExc(e: ref Exception) {.compilerproc, inline.} =
|
||||
sysFatal(ReraiseError, "exception handling is not available")
|
||||
sysFatal(ReraiseDefect, "exception handling is not available")
|
||||
|
|
|
|||
|
|
@ -62,19 +62,19 @@ type
|
|||
## Raised if a dynamic library could not be loaded.
|
||||
ResourceExhaustedError* = object of CatchableError ## \
|
||||
## Raised if a resource request could not be fulfilled.
|
||||
ArithmeticError* = object of Defect ## \
|
||||
ArithmeticDefect* = object of Defect ## \
|
||||
## Raised if any kind of arithmetic error occurred.
|
||||
DivByZeroError* = object of ArithmeticError ## \
|
||||
DivByZeroDefect* = object of ArithmeticDefect ## \
|
||||
## Raised for runtime integer divide-by-zero errors.
|
||||
|
||||
OverflowError* = object of ArithmeticError ## \
|
||||
OverflowDefect* = object of ArithmeticDefect ## \
|
||||
## Raised for runtime integer overflows.
|
||||
##
|
||||
## This happens for calculations whose results are too large to fit in the
|
||||
## provided bits.
|
||||
AccessViolationError* = object of Defect ## \
|
||||
AccessViolationDefect* = object of Defect ## \
|
||||
## Raised for invalid memory access errors
|
||||
AssertionError* = object of Defect ## \
|
||||
AssertionDefect* = object of Defect ## \
|
||||
## Raised when assertion is proved wrong.
|
||||
##
|
||||
## Usually the result of using the `assert() template
|
||||
|
|
@ -87,54 +87,77 @@ type
|
|||
## Mostly used by the `tables <tables.html>`_ module, it can also be raised
|
||||
## by other collection modules like `sets <sets.html>`_ or `strtabs
|
||||
## <strtabs.html>`_.
|
||||
OutOfMemError* = object of Defect ## \
|
||||
OutOfMemDefect* = object of Defect ## \
|
||||
## Raised for unsuccessful attempts to allocate memory.
|
||||
IndexError* = object of Defect ## \
|
||||
IndexDefect* = object of Defect ## \
|
||||
## Raised if an array index is out of bounds.
|
||||
|
||||
FieldError* = object of Defect ## \
|
||||
FieldDefect* = object of Defect ## \
|
||||
## Raised if a record field is not accessible because its discriminant's
|
||||
## value does not fit.
|
||||
RangeError* = object of Defect ## \
|
||||
RangeDefect* = object of Defect ## \
|
||||
## Raised if a range check error occurred.
|
||||
StackOverflowError* = object of Defect ## \
|
||||
StackOverflowDefect* = object of Defect ## \
|
||||
## Raised if the hardware stack used for subroutine calls overflowed.
|
||||
ReraiseError* = object of Defect ## \
|
||||
ReraiseDefect* = object of Defect ## \
|
||||
## Raised if there is no exception to reraise.
|
||||
ObjectAssignmentError* = object of Defect ## \
|
||||
ObjectAssignmentDefect* = object of Defect ## \
|
||||
## Raised if an object gets assigned to its parent's object.
|
||||
ObjectConversionError* = object of Defect ## \
|
||||
ObjectConversionDefect* = object of Defect ## \
|
||||
## Raised if an object is converted to an incompatible object type.
|
||||
## You can use ``of`` operator to check if conversion will succeed.
|
||||
FloatingPointError* = object of Defect ## \
|
||||
FloatingPointDefect* = object of Defect ## \
|
||||
## Base class for floating point exceptions.
|
||||
FloatInvalidOpError* = object of FloatingPointError ## \
|
||||
FloatInvalidOpDefect* = object of FloatingPointDefect ## \
|
||||
## Raised by invalid operations according to IEEE.
|
||||
##
|
||||
## Raised by ``0.0/0.0``, for example.
|
||||
FloatDivByZeroError* = object of FloatingPointError ## \
|
||||
FloatDivByZeroDefect* = object of FloatingPointDefect ## \
|
||||
## Raised by division by zero.
|
||||
##
|
||||
## Divisor is zero and dividend is a finite nonzero number.
|
||||
FloatOverflowError* = object of FloatingPointError ## \
|
||||
FloatOverflowDefect* = object of FloatingPointDefect ## \
|
||||
## Raised for overflows.
|
||||
##
|
||||
## The operation produced a result that exceeds the range of the exponent.
|
||||
FloatUnderflowError* = object of FloatingPointError ## \
|
||||
FloatUnderflowDefect* = object of FloatingPointDefect ## \
|
||||
## Raised for underflows.
|
||||
##
|
||||
## The operation produced a result that is too small to be represented as a
|
||||
## normal number.
|
||||
FloatInexactError* = object of FloatingPointError ## \
|
||||
FloatInexactDefect* = object of FloatingPointDefect ## \
|
||||
## Raised for inexact results.
|
||||
##
|
||||
## The operation produced a result that cannot be represented with infinite
|
||||
## precision -- for example: ``2.0 / 3.0, log(1.1)``
|
||||
##
|
||||
## **Note**: Nim currently does not detect these!
|
||||
DeadThreadError* = object of Defect ## \
|
||||
DeadThreadDefect* = object of Defect ## \
|
||||
## Raised if it is attempted to send a message to a dead thread.
|
||||
NilAccessError* = object of Defect ## \
|
||||
NilAccessDefect* = object of Defect ## \
|
||||
## Raised on dereferences of ``nil`` pointers.
|
||||
##
|
||||
## This is only raised if the `segfaults module <segfaults.html>`_ was imported!
|
||||
|
||||
ArithmeticError* {.deprecated: "See corresponding Defect".} = ArithmeticDefect
|
||||
DivByZeroError* {.deprecated: "See corresponding Defect".} = ArithmeticDefect
|
||||
OverflowError* {.deprecated: "See corresponding Defect".} = OverflowDefect
|
||||
AccessViolationError* {.deprecated: "See corresponding Defect".} = AccessViolationDefect
|
||||
AssertionError* {.deprecated: "See corresponding Defect".} = AssertionDefect
|
||||
OutOfMemError* {.deprecated: "See corresponding Defect".} = OutOfMemDefect
|
||||
IndexError* {.deprecated: "See corresponding Defect".} = IndexDefect
|
||||
|
||||
FieldError* {.deprecated: "See corresponding Defect".} = FieldDefect
|
||||
RangeError* {.deprecated: "See corresponding Defect".} = RangeDefect
|
||||
StackOverflowError* {.deprecated: "See corresponding Defect".} = StackOverflowDefect
|
||||
ReraiseError* {.deprecated: "See corresponding Defect".} = ReraiseDefect
|
||||
ObjectAssignmentError* {.deprecated: "See corresponding Defect".} = ObjectAssignmentDefect
|
||||
ObjectConversionError* {.deprecated: "See corresponding Defect".} = ObjectConversionDefect
|
||||
FloatingPointError* {.deprecated: "See corresponding Defect".} = FloatingPointDefect
|
||||
FloatInvalidOpError* {.deprecated: "See corresponding Defect".} = FloatInvalidOpDefect
|
||||
FloatDivByZeroError* {.deprecated: "See corresponding Defect".} = FloatDivByZeroDefect
|
||||
FloatOverflowError* {.deprecated: "See corresponding Defect".} = FloatOverflowDefect
|
||||
FloatUnderflowError* {.deprecated: "See corresponding Defect".} = FloatUnderflowDefect
|
||||
FloatInexactError* {.deprecated: "See corresponding Defect".} = FloatInexactDefect
|
||||
DeadThreadError* {.deprecated: "See corresponding Defect".} = DeadThreadDefect
|
||||
NilAccessError* {.deprecated: "See corresponding Defect".} = NilAccessDefect
|
||||
|
|
|
|||
|
|
@ -483,7 +483,7 @@ proc raiseException(e: sink(ref Exception), ename: cstring) {.compilerRtl.} =
|
|||
|
||||
proc reraiseException() {.compilerRtl.} =
|
||||
if currException == nil:
|
||||
sysFatal(ReraiseError, "no exception to reraise")
|
||||
sysFatal(ReraiseDefect, "no exception to reraise")
|
||||
else:
|
||||
when gotoBasedExceptions:
|
||||
inc nimInErrorMode
|
||||
|
|
|
|||
|
|
@ -844,7 +844,7 @@ when not defined(useNimRtl):
|
|||
inc(gch.recGcLock)
|
||||
proc GC_enable() =
|
||||
if gch.recGcLock <= 0:
|
||||
raise newException(AssertionError,
|
||||
raise newException(AssertionDefect,
|
||||
"API usage error: GC_enable called but GC is already enabled")
|
||||
dec(gch.recGcLock)
|
||||
|
||||
|
|
|
|||
|
|
@ -496,7 +496,7 @@ when not defined(useNimRtl):
|
|||
inc(gch.recGcLock)
|
||||
proc GC_enable() =
|
||||
if gch.recGcLock <= 0:
|
||||
raise newException(AssertionError,
|
||||
raise newException(AssertionDefect,
|
||||
"API usage error: GC_enable called but GC is already enabled")
|
||||
dec(gch.recGcLock)
|
||||
|
||||
|
|
|
|||
|
|
@ -12,10 +12,10 @@
|
|||
|
||||
proc raiseOverflow {.compilerproc, noinline.} =
|
||||
# a single proc to reduce code size to a minimum
|
||||
sysFatal(OverflowError, "over- or underflow")
|
||||
sysFatal(OverflowDefect, "over- or underflow")
|
||||
|
||||
proc raiseDivByZero {.compilerproc, noinline.} =
|
||||
sysFatal(DivByZeroError, "division by zero")
|
||||
sysFatal(DivByZeroDefect, "division by zero")
|
||||
|
||||
{.pragma: nimbaseH, importc, nodecl, noSideEffect, compilerproc.}
|
||||
|
||||
|
|
@ -123,10 +123,10 @@ divImplFallback(nimDivInt, int)
|
|||
divImplFallback(nimDivInt64, int64)
|
||||
|
||||
proc raiseFloatInvalidOp {.compilerproc, noinline.} =
|
||||
sysFatal(FloatInvalidOpError, "FPU operation caused a NaN result")
|
||||
sysFatal(FloatInvalidOpDefect, "FPU operation caused a NaN result")
|
||||
|
||||
proc raiseFloatOverflow(x: float64) {.compilerproc, noinline.} =
|
||||
if x > 0.0:
|
||||
sysFatal(FloatOverflowError, "FPU operation caused an overflow")
|
||||
sysFatal(FloatOverflowDefect, "FPU operation caused an overflow")
|
||||
else:
|
||||
sysFatal(FloatUnderflowError, "FPU operations caused an underflow")
|
||||
sysFatal(FloatUnderflowDefect, "FPU operations caused an underflow")
|
||||
|
|
|
|||
|
|
@ -142,7 +142,7 @@ proc raiseException(e: ref Exception, ename: cstring) {.
|
|||
|
||||
proc reraiseException() {.compilerproc, asmNoStackFrame.} =
|
||||
if lastJSError == nil:
|
||||
raise newException(ReraiseError, "no exception to reraise")
|
||||
raise newException(ReraiseDefect, "no exception to reraise")
|
||||
else:
|
||||
if excHandler == 0:
|
||||
if isNimException():
|
||||
|
|
@ -151,19 +151,19 @@ proc reraiseException() {.compilerproc, asmNoStackFrame.} =
|
|||
asm "throw lastJSError;"
|
||||
|
||||
proc raiseOverflow {.exportc: "raiseOverflow", noreturn, compilerproc.} =
|
||||
raise newException(OverflowError, "over- or underflow")
|
||||
raise newException(OverflowDefect, "over- or underflow")
|
||||
|
||||
proc raiseDivByZero {.exportc: "raiseDivByZero", noreturn, compilerproc.} =
|
||||
raise newException(DivByZeroError, "division by zero")
|
||||
raise newException(DivByZeroDefect, "division by zero")
|
||||
|
||||
proc raiseRangeError() {.compilerproc, noreturn.} =
|
||||
raise newException(RangeError, "value out of range")
|
||||
raise newException(RangeDefect, "value out of range")
|
||||
|
||||
proc raiseIndexError(i, a, b: int) {.compilerproc, noreturn.} =
|
||||
raise newException(IndexError, formatErrorIndexBound(int(i), int(a), int(b)))
|
||||
raise newException(IndexDefect, formatErrorIndexBound(int(i), int(a), int(b)))
|
||||
|
||||
proc raiseFieldError(f: string) {.compilerproc, noreturn.} =
|
||||
raise newException(FieldError, f)
|
||||
raise newException(FieldDefect, f)
|
||||
|
||||
proc setConstr() {.varargs, asmNoStackFrame, compilerproc.} =
|
||||
asm """
|
||||
|
|
@ -524,7 +524,7 @@ proc nimMax(a, b: int): int {.compilerproc.} = return if a >= b: a else: b
|
|||
|
||||
proc chckNilDisp(p: pointer) {.compilerproc.} =
|
||||
if p == nil:
|
||||
sysFatal(NilAccessError, "cannot dispatch; dispatcher is nil")
|
||||
sysFatal(NilAccessDefect, "cannot dispatch; dispatcher is nil")
|
||||
|
||||
include "system/hti"
|
||||
|
||||
|
|
@ -663,7 +663,7 @@ proc chckObj(obj, subclass: PNimType) {.compilerproc.} =
|
|||
if x == subclass: return # optimized fast path
|
||||
while x != subclass:
|
||||
if x == nil:
|
||||
raise newException(ObjectConversionError, "invalid object conversion")
|
||||
raise newException(ObjectConversionDefect, "invalid object conversion")
|
||||
x = x.base
|
||||
|
||||
proc isObj(obj, subclass: PNimType): bool {.compilerproc.} =
|
||||
|
|
|
|||
|
|
@ -191,4 +191,4 @@ proc isObj(obj: PNimType, subclass: cstring): bool {.compilerRtl, inl.} =
|
|||
|
||||
proc chckObj(obj: PNimType, subclass: cstring) {.compilerRtl.} =
|
||||
# checks if obj is of type subclass:
|
||||
if not isObj(obj, subclass): sysFatal(ObjectConversionError, "invalid object conversion")
|
||||
if not isObj(obj, subclass): sysFatal(ObjectConversionDefect, "invalid object conversion")
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue