[issue35446] incorrect example
New submission from Alistsair Lenhard <alistair.lenhard@googlemail.com>: under: https://docs.python.org/3/tutorial/errors.html Original it says: "Note that if the except clauses were reversed (with except B first), it would have printed B, B, B — the first matching except clause is triggered." It should read: "Note that if the except clauses were reversed (with except B first), it would have printed D, D, D — the first matching except clause is triggered." As D is the first expression in the print statement. So if the expression is changed to "except B:" class B(Exception): pass class C(B): pass class D(C): pass for cls in [B, C, D]: try: raise cls() except B: print("D") except C: print("C") except B: print("B") Result is: D D D ---------- assignee: docs@python components: Documentation messages: 331428 nosy: Alistair, docs@python priority: normal severity: normal status: open title: incorrect example versions: Python 3.7 _______________________________________ Python tracker <report@bugs.python.org> <https://bugs.python.org/issue35446> _______________________________________
Martin Panter <vadmium+py@gmail.com> added the comment: It doesn’t make sense to move the “except” line without moving the matching “print” line. According to <https://docs.python.org/3.7/reference/compound_stmts.html#index-1>, “A clause consists of a header and a ‘suite’.” So when it talks about reversing the “except” clauses, that includes reversing the corresponding “print” lines, so they condinue to identify which exception handler was triggered. ---------- nosy: +martin.panter _______________________________________ Python tracker <report@bugs.python.org> <https://bugs.python.org/issue35446> _______________________________________
Serhiy Storchaka <storchaka+cpython@gmail.com> added the comment: The example is correct. If the except clauses were reversed for cls in [B, C, D]: try: raise cls() except B: print("B") except C: print("C") except D: print("D") it would have printed B, B, B. ---------- nosy: +serhiy.storchaka resolution: -> not a bug stage: -> resolved status: open -> closed _______________________________________ Python tracker <report@bugs.python.org> <https://bugs.python.org/issue35446> _______________________________________
Change by Eric Snow <ericsnowcurrently@gmail.com>: ---------- pull_requests: +10353 _______________________________________ Python tracker <report@bugs.python.org> <https://bugs.python.org/issue35446> _______________________________________
Change by Eric Snow <ericsnowcurrently@gmail.com>: ---------- pull_requests: -10353 _______________________________________ Python tracker <report@bugs.python.org> <https://bugs.python.org/issue35446> _______________________________________
participants (4)
-
Alistsair Lenhard
-
Eric Snow
-
Martin Panter
-
Serhiy Storchaka