diff options
author | Jacek Sieka <arnetheduck@gmail.com> | 2020-04-28 19:56:01 +0200 |
---|---|---|
committer | GitHub <noreply@github.com> | 2020-04-28 19:56:01 +0200 |
commit | 7d6cbf290a5e0cbce14b9926f57221a017f20a4a (patch) | |
tree | f8bf7d55e271571ebbb817ff28858c29e712382b /doc | |
parent | cd9af6b8040bc72985d457e5169e18ded7c107d6 (diff) | |
download | Nim-7d6cbf290a5e0cbce14b9926f57221a017f20a4a.tar.gz |
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.
Diffstat (limited to 'doc')
-rw-r--r-- | doc/lib.rst | 2 | ||||
-rw-r--r-- | doc/manual.rst | 28 | ||||
-rw-r--r-- | doc/tut2.rst | 8 | ||||
-rw-r--r-- | doc/tut3.rst | 4 |
4 files changed, 21 insertions, 21 deletions
diff --git a/doc/lib.rst b/doc/lib.rst index 9252ec7a0..97f6c1db1 100644 --- a/doc/lib.rst +++ b/doc/lib.rst @@ -451,7 +451,7 @@ Miscellaneous This module implements a simple logger. * `segfaults <segfaults.html>`_ - Turns access violations or segfaults into a ``NilAccessError`` exception. + Turns access violations or segfaults into a ``NilAccessDefect`` exception. * `sugar <sugar.html>`_ This module implements nice syntactic sugar based on Nim's macro system. diff --git a/doc/manual.rst b/doc/manual.rst index 8cfb08cdb..3933a9297 100644 --- a/doc/manual.rst +++ b/doc/manual.rst @@ -113,7 +113,7 @@ pragmas_ for details. Whether a panic results in an exception or in a fatal error is implementation specific. Thus the following program is invalid; even though the -code purports to catch the `IndexError` from an out-of-bounds array access, the +code purports to catch the `IndexDefect` from an out-of-bounds array access, the compiler may instead choose to allow the program to die with a fatal error. .. code-block:: nim @@ -121,7 +121,7 @@ compiler may instead choose to allow the program to die with a fatal error. let i = 5 try: a[i] = 'N' - except IndexError: + except IndexDefect: echo "invalid index" The current implementation allows to switch between these different behaviors @@ -1033,10 +1033,10 @@ The IEEE standard defines five types of floating-point exceptions: precision, for example, 2.0 / 3.0, log(1.1) and 0.1 in input. The IEEE exceptions are either ignored during execution or mapped to the -Nim exceptions: `FloatInvalidOpError`:idx:, `FloatDivByZeroError`:idx:, -`FloatOverflowError`:idx:, `FloatUnderflowError`:idx:, -and `FloatInexactError`:idx:. -These exceptions inherit from the `FloatingPointError`:idx: base class. +Nim exceptions: `FloatInvalidOpDefect`:idx:, `FloatDivByZeroDefect`:idx:, +`FloatOverflowDefect`:idx:, `FloatUnderflowDefect`:idx:, +and `FloatInexactDefect`:idx:. +These exceptions inherit from the `FloatingPointDefect`:idx: base class. Nim provides the pragmas `nanChecks`:idx: and `infChecks`:idx: to control whether the IEEE exceptions are ignored or trap a Nim exception: @@ -1045,12 +1045,12 @@ whether the IEEE exceptions are ignored or trap a Nim exception: {.nanChecks: on, infChecks: on.} var a = 1.0 var b = 0.0 - echo b / b # raises FloatInvalidOpError - echo a / b # raises FloatOverflowError + echo b / b # raises FloatInvalidOpDefect + echo a / b # raises FloatOverflowDefect -In the current implementation ``FloatDivByZeroError`` and ``FloatInexactError`` -are never raised. ``FloatOverflowError`` is raised instead of -``FloatDivByZeroError``. +In the current implementation ``FloatDivByZeroDefect`` and ``FloatInexactDefect`` +are never raised. ``FloatOverflowDefect`` is raised instead of +``FloatDivByZeroDefect``. There is also a `floatChecks`:idx: pragma that is a short-cut for the combination of ``nanChecks`` and ``infChecks`` pragmas. ``floatChecks`` are turned off as default. @@ -1620,7 +1620,7 @@ An example: # accessing n.thenPart is valid because the ``nkIf`` branch is active: n.thenPart = Node(kind: nkFloat, floatVal: 2.0) - # the following statement raises an `FieldError` exception, because + # the following statement raises an `FieldDefect` exception, because # n.kind's value does not fit and the ``nkString`` branch is not active: n.strVal = "" @@ -4063,7 +4063,7 @@ Example: var a = readLine(f) var b = readLine(f) echo "sum: " & $(parseInt(a) + parseInt(b)) - except OverflowError: + except OverflowDefect: echo "overflow!" except ValueError: echo "could not convert string to integer" @@ -4226,7 +4226,7 @@ the ``raise`` statement is the only way to raise an exception. .. XXX document this better! If no exception name is given, the current exception is `re-raised`:idx:. The -`ReraiseError`:idx: exception is raised if there is no exception to +`ReraiseDefect`:idx: exception is raised if there is no exception to re-raise. It follows that the ``raise`` statement *always* raises an exception. diff --git a/doc/tut2.rst b/doc/tut2.rst index 0338bdb1a..ac8e82b0a 100644 --- a/doc/tut2.rst +++ b/doc/tut2.rst @@ -126,7 +126,7 @@ The syntax for type conversions is ``destination_type(expression_to_convert)`` proc getID(x: Person): int = Student(x).id -The ``InvalidObjectConversionError`` exception is raised if ``x`` is not a +The ``InvalidObjectConversionDefect`` exception is raised if ``x`` is not a ``Student``. @@ -160,7 +160,7 @@ An example: condition, thenPart, elsePart: Node var n = Node(kind: nkFloat, floatVal: 1.0) - # the following statement raises an `FieldError` exception, because + # the following statement raises an `FieldDefect` exception, because # n.kind's value does not fit: n.strVal = "" @@ -388,7 +388,7 @@ The ``try`` statement handles exceptions: let a = readLine(f) let b = readLine(f) echo "sum: ", parseInt(a) + parseInt(b) - except OverflowError: + except OverflowDefect: echo "overflow!" except ValueError: echo "could not convert string to integer" @@ -443,7 +443,7 @@ instance, if you specify that a proc raises ``IOError``, and at some point it prevent that proc from compiling. Usage example: .. code-block:: nim - proc complexProc() {.raises: [IOError, ArithmeticError].} = + proc complexProc() {.raises: [IOError, ArithmeticDefect].} = ... proc simpleProc() {.raises: [].} = diff --git a/doc/tut3.rst b/doc/tut3.rst index 2feae1f7d..a39074db9 100644 --- a/doc/tut3.rst +++ b/doc/tut3.rst @@ -271,7 +271,7 @@ written. result = quote do: if not `arg`: - raise newException(AssertionError,$`lhs` & `op` & $`rhs`) + raise newException(AssertionDefect,$`lhs` & `op` & $`rhs`) let a = 1 let b = 2 @@ -287,7 +287,7 @@ used to get this output. .. code-block:: nim if not (a != b): - raise newException(AssertionError, $a & " != " & $b) + raise newException(AssertionDefect, $a & " != " & $b) With Power Comes Responsibility ------------------------------- |