Update documentation to cover new 'try' body rules

This commit is contained in:
Rob Day 2017-12-03 09:45:57 +00:00
parent eda78eb81c
commit 76bbf05812

View File

@ -1666,6 +1666,7 @@ actions (``finally``).
(try (try
(error-prone-function) (error-prone-function)
(another-error-prone-function)
(except [ZeroDivisionError] (except [ZeroDivisionError]
(print "Division by zero")) (print "Division by zero"))
(except [[IndexError KeyboardInterrupt]] (except [[IndexError KeyboardInterrupt]]
@ -1679,13 +1680,13 @@ actions (``finally``).
(finally (finally
(print "All done"))) (print "All done")))
The first argument of ``try`` is its body. (To put more than one form in the The first argument of ``try`` is its body, which can contain one or more forms.
body, use ``do``.) Then comes any number of ``except`` clauses, then optionally Then comes any number of ``except`` clauses, then optionally an ``else``
an ``else`` clause, then optionally a ``finally`` clause. If an exception is clause, then optionally a ``finally`` clause. If an exception is raised with a
raised with a matching ``except`` clause during the execution of the body, that matching ``except`` clause during the execution of the body, that ``except``
``except`` clause will be executed. If no exceptions are raised, the ``else`` clause will be executed. If no exceptions are raised, the ``else`` clause is
clause is executed. The ``finally`` clause will be executed last regardless of executed. The ``finally`` clause will be executed last regardless of whether an
whether an exception was raised. exception was raised.
The return value of ``try`` is the last form of the ``except`` clause that was The return value of ``try`` is the last form of the ``except`` clause that was
run, or the last form of ``else`` if no exception was raised, or the ``try`` run, or the last form of ``else`` if no exception was raised, or the ``try``