From 03c146cd93ba48f7e8cab05e6214c8675d0dd1f9 Mon Sep 17 00:00:00 2001 From: Andreas Rumpf Date: Mon, 11 May 2020 16:25:56 +0200 Subject: 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 --- doc/manual.rst | 22 ++++++++++++++++++++++ 1 file changed, 22 insertions(+) (limited to 'doc') diff --git a/doc/manual.rst b/doc/manual.rst index 02ccace2c..6feb8aebb 100644 --- a/doc/manual.rst +++ b/doc/manual.rst @@ -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 ------------ -- cgit 1.4.1-2-gfad0