@@ -82,6 +82,9 @@ msgid ""
8282"that is eventually displayed will include the originating exception(s) and "
8383"the final exception."
8484msgstr ""
85+ "当在 :keyword:`except` 或 :keyword:`finally` "
86+ "子句中引发(或重新引发)异常时,:attr:`__context__` "
87+ "会被自动设为所捕获的最后一个异常;如果新的异常未被处理,则最终显示的回溯信息将包括原始的异常和最后的异常。"
8588
8689#: ../../library/exceptions.rst:43
8790msgid ""
@@ -90,6 +93,8 @@ msgid ""
9093"be supplemented with an explicit cause by using :keyword:`from` with "
9194":keyword:`raise`::"
9295msgstr ""
96+ "当引发一个新的异常(而不是简单地使用 ``raise`` 来重新引发当前在处理的异常)时,隐式的异常上下文可以通过使用带有 "
97+ ":keyword:`raise` 的 :keyword:`from` 来补充一个显式的原因::"
9398
9499#: ../../library/exceptions.rst:50
95100msgid ""
@@ -101,6 +106,11 @@ msgid ""
101106"converting :exc:`KeyError` to :exc:`AttributeError`), while leaving the old "
102107"exception available in :attr:`__context__` for introspection when debugging."
103108msgstr ""
109+ "跟在 :keyword:`from` 之后的表达式必须为一个异常或 ``None``。 它将在所引发的异常上被设置为 "
110+ ":attr:`__cause__`。 设置 :attr:`__cause__` 还会隐式地将 :attr:`__suppress_context__` "
111+ "属性设为 ``True``,这样使用 ``raise new_exc from None`` 可以有效地将旧异常替换为新异常来显示其目的 (例如将 "
112+ ":exc:`KeyError` 转换为 :exc:`AttributeError`),同时让旧异常在 :attr:`__context__` "
113+ "中保持可用状态以便在调试时进行内省。"
104114
105115#: ../../library/exceptions.rst:59
106116msgid ""
@@ -110,13 +120,16 @@ msgid ""
110120"chained exception in :attr:`__context__` is shown only if :attr:`__cause__` "
111121"is :const:`None` and :attr:`__suppress_context__` is false."
112122msgstr ""
123+ "除了异常本身的回溯以外,默认的回溯还会显示这些串连的异常。 :attr:`__cause__` 中的显式串连异常如果存在将总是显示。 "
124+ ":attr:`__context__` 中的隐式串连异常仅在 :attr:`__cause__` 为 :const:`None` 并且 "
125+ ":attr:`__suppress_context__` 为假值时显示。"
113126
114127#: ../../library/exceptions.rst:65
115128msgid ""
116129"In either case, the exception itself is always shown after any chained "
117130"exceptions so that the final line of the traceback always shows the last "
118131"exception that was raised."
119- msgstr ""
132+ msgstr "不论在哪种情况下,异常本身总会在任何串连异常之后显示,以便回溯的最后一行总是显示所引发的最后一个异常。 "
120133
121134#: ../../library/exceptions.rst:71
122135msgid "Base classes"
0 commit comments