do not track 'raise Defect' in the .raises: [] clause anymore (#14298)
* do not track 'raise Defect' in the .raises: [] clause anymore * --panics:on maps 'raise Defect' to an unrecoverable fatal error * make tests green again * update the documentation too
This commit is contained in:
parent
517dd800f8
commit
03c146cd93
6 changed files with 74 additions and 8 deletions
|
|
@ -4338,6 +4338,28 @@ Rules 1-2 ensure the following works:
|
|||
So in many cases a callback does not cause the compiler to be overly
|
||||
conservative in its effect analysis.
|
||||
|
||||
Exceptions inheriting from ``system.Defect`` are not tracked with
|
||||
the ``.raises: []`` exception tracking mechanism. This is more consistent with the
|
||||
built-in operations. The following code is valid::
|
||||
|
||||
.. code-block:: nim
|
||||
|
||||
proc mydiv(a, b): int {.raises: [].} =
|
||||
a div b # can raise an DivByZeroDefect
|
||||
|
||||
And so is::
|
||||
|
||||
.. code-block:: nim
|
||||
|
||||
proc mydiv(a, b): int {.raises: [].} =
|
||||
if b == 0: raise newException(DivByZeroDefect, "division by zero")
|
||||
else: result = a div b
|
||||
|
||||
|
||||
The reason for this is that ``DivByZeroDefect`` inherits from ``Defect`` and
|
||||
with ``--panics:on`` Defects become unrecoverable errors.
|
||||
(Since version 1.4 of the language.)
|
||||
|
||||
|
||||
Tag tracking
|
||||
------------
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue