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
|
|
@ -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
|
||||
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue