diff --git a/library/exceptions.po b/library/exceptions.po index 2b28c6d433..dabf3ed246 100644 --- a/library/exceptions.po +++ b/library/exceptions.po @@ -9,7 +9,7 @@ msgstr "" "Project-Id-Version: Python 3.12\n" "Report-Msgid-Bugs-To: \n" "POT-Creation-Date: 2024-03-01 00:03+0000\n" -"PO-Revision-Date: 2018-05-23 16:01+0000\n" +"PO-Revision-Date: 2024-03-12 20:57+0800\n" "Last-Translator: Adrian Liaw \n" "Language-Team: Chinese - TAIWAN (https://github.com/python/python-docs-zh-" "tw)\n" @@ -18,6 +18,7 @@ msgstr "" "Content-Type: text/plain; charset=UTF-8\n" "Content-Transfer-Encoding: 8bit\n" "Plural-Forms: nplurals=1; plural=0;\n" +"X-Generator: Poedit 3.4.2\n" #: ../../library/exceptions.rst:4 msgid "Built-in Exceptions" @@ -32,6 +33,11 @@ msgid "" "from which *it* is derived). Two exception classes that are not related via " "subclassing are never equivalent, even if they have the same name." msgstr "" +"在 Python 中,所有例外必須是從 :class:`BaseException` 衍生的類別的實例。在陳" +"述式 :keyword:`try` 搭配 :keyword:`except` 子句裡提到一個特定的類別時,那個子" +"句也會處理任何從該類別衍生的例外類別(但不會處理該類別\\ *衍生自*\\ 的例外類" +"別)。兩個不是由子類別關係關聯起來的例外類別永遠不相等,就算它們有相同的名稱" +"也是如此。" #: ../../library/exceptions.rst:19 msgid "" @@ -42,6 +48,10 @@ msgid "" "and a string explaining the code). The associated value is usually passed " "as arguments to the exception class's constructor." msgstr "" +"此章節裡列出的內建例外可以從直譯器或內建函式產生。除了特別提到的地方之外,它" +"們會有一個\\ *關聯值*\\ 表示錯誤發生的詳細原因。這可能是一個字串,或者是一些" +"資訊項目組成的元組(例如一個錯誤代碼及一個解釋該代碼的字串)。這個關聯值通常" +"當作引數傳遞給例外類別的建構函式。" #: ../../library/exceptions.rst:26 msgid "" @@ -51,6 +61,9 @@ msgid "" "that there is nothing to prevent user code from raising an inappropriate " "error." msgstr "" +"使用者的程式碼可以引發內建例外。這可以用來測試例外處理器或者用來回報一個錯誤" +"條件,*就像*\\ 直譯器會引發相同例外的情況;但需要注意的是沒有任何方式可以避免" +"使用者的程式碼引發不適當的錯誤。" #: ../../library/exceptions.rst:31 msgid "" @@ -60,16 +73,19 @@ msgid "" "`BaseException`. More information on defining exceptions is available in " "the Python Tutorial under :ref:`tut-userexceptions`." msgstr "" +"可以從內建的例外類別定義新的例外子類別;程式設計師被鼓勵從 :exc:`Exception` " +"類別或其子類別衍生新的例外,而不是從 :exc:`BaseException` 來衍生。更多關於定" +"義例外的資訊可以在 Python 教學中的\\ :ref:`tut-userexceptions`\\ 裡取得。" #: ../../library/exceptions.rst:39 msgid "Exception context" -msgstr "" +msgstr "例外的情境" #: ../../library/exceptions.rst:46 msgid "" "Three attributes on exception objects provide information about the context " "in which the exception was raised:" -msgstr "" +msgstr "三個例外物件上的屬性提供關於引發此例外的情境的資訊:" #: ../../library/exceptions.rst:53 msgid "" @@ -79,12 +95,17 @@ msgid "" "`except` or :keyword:`finally` clause, or a :keyword:`with` statement, is " "used." msgstr "" +"當引發一個新的例外而同時有另一個例外已經正在被處理時,這個新例外的 :attr:`!" +"__context__` 屬性會自動被設成那個已處理的例外。當使用 :keyword:`except` 或 :" +"keyword:`finally` 子句或 :keyword:`with` 陳述式的時候例外會被處理。" #: ../../library/exceptions.rst:59 msgid "" "This implicit exception context can be supplemented with an explicit cause " "by using :keyword:`!from` with :keyword:`raise`::" msgstr "" +"這個隱含的例外情境可以透過使用 :keyword:`!from` 搭配 :keyword:`raise` 來補充" +"明確的原因: ::" #: ../../library/exceptions.rst:65 msgid "" @@ -97,6 +118,12 @@ msgid "" "while leaving the old exception available in :attr:`!__context__` for " "introspection when debugging." msgstr "" +"在 :keyword:`from` 後面的運算式必須是一個例外或 ``None``。它將會被設定" +"成所引發例外的 :attr:`!__cause__`。設定 :attr:`!__cause__` 也隱含地設定 :" +"attr:`!__suppress_context__` 屬性為 ``True``,因此使用 ``raise new_exc from " +"None`` 實際上會以新的例外取代舊的例外以利於顯示(例如轉換 :exc:`KeyError` " +"為 :exc:`AttributeError`),同時保持舊的例外可以透過 :attr:`!__context__` 取" +"得以方便 debug 的時候檢查。" #: ../../library/exceptions.rst:74 msgid "" @@ -106,6 +133,11 @@ msgid "" "chained exception in :attr:`!__context__` is shown only if :attr:`!" "__cause__` is :const:`None` and :attr:`!__suppress_context__` is false." msgstr "" +"預設的回溯 (traceback) 顯示程式碼會顯示這些連鎖的例外 (chained exception) 加" +"上例外本身的回溯。當存在的時候,在 :attr:`!__cause__` 中明確地連鎖的例外總是" +"會被顯示。而在 :attr:`!__context__` 中隱含地連鎖的例外只有當 :attr:`!" +"__cause__` 是 :const:`None` 且 :attr:`!__suppress_context__` 是 false 時才會" +"顯示。" #: ../../library/exceptions.rst:80 msgid "" @@ -113,6 +145,8 @@ msgid "" "exceptions so that the final line of the traceback always shows the last " "exception that was raised." msgstr "" +"在任一種情況下,例外本身總是會顯示在任何連鎖例外的後面,因此回溯的最後一行總" +"是顯示最後一個被引發的例外。" #: ../../library/exceptions.rst:86 msgid "Inheriting from built-in exceptions" @@ -125,6 +159,9 @@ msgid "" "possible conflicts between how the bases handle the ``args`` attribute, as " "well as due to possible memory layout incompatibilities." msgstr "" +"使用者的程式碼可以建立繼承自例外類型的子類別。建議一次只繼承一種例外類型以避" +"免在基底類別之間如何處理 ``args`` 屬性的任何可能衝突,以及可能的記憶體佈局 " +"(memory layout) 不相容。" #: ../../library/exceptions.rst:95 msgid "" @@ -135,16 +172,20 @@ msgid "" "between Python versions, leading to new conflicts in the future. Therefore, " "it's recommended to avoid subclassing multiple exception types altogether." msgstr "" +"為了效率,大部分的內建例外使用 C 來實作,參考 :source:`Objects/exceptions." +"c`。一些例外有客製化的記憶體佈局,使其不可能建立一個繼承多種例外類型的子類" +"別。類型的記憶體佈局是實作細節且可能會在不同 Python 版本間改變,造成未來新的" +"衝突。因此,總之建議避免繼承多種例外類型。" #: ../../library/exceptions.rst:105 msgid "Base classes" -msgstr "" +msgstr "基底類別 (base classes)" #: ../../library/exceptions.rst:107 msgid "" "The following exceptions are used mostly as base classes for other " "exceptions." -msgstr "" +msgstr "以下的例外大部分被用在當作其他例外的基底類別。" #: ../../library/exceptions.rst:111 msgid "" @@ -154,6 +195,9 @@ msgid "" "argument(s) to the instance are returned, or the empty string when there " "were no arguments." msgstr "" +"所有內建例外的基底類別。這不是為了讓使用者定義的類別直接繼承(可以使用 :exc:" +"`Exception`)。如果在這個類別的實例上呼叫 :func:`str`,會回傳實例的引數的表" +"示,或者沒有引數的時候會回傳空字串。" #: ../../library/exceptions.rst:119 msgid "" @@ -162,6 +206,9 @@ msgid "" "assign a special meaning to the elements of this tuple, while others are " "usually called only with a single string giving an error message." msgstr "" +"提供給該例外建構函式的引數元組。一些內建的例外(像是 :exc:`OSError`)預期接受" +"特定數量的引數並賦予該元組的每一個元素一個特別的意義,其他例外則通常用一個提" +"供錯誤訊息的單一字串來呼叫。" #: ../../library/exceptions.rst:126 msgid "" @@ -174,12 +221,19 @@ msgid "" "happened to the traceback of the original ``SomeException`` had we allowed " "it to propagate to the caller. ::" msgstr "" +"此方法設定 *tb* 為該例外的新的回溯並回傳該例外物件。在 :pep:`3134` 的例外連鎖" +"功能變得可用之前,此方法曾被更普遍使用。下面的範例顯示我們如何將 " +"``SomeException`` 的實例轉換為 ``OtherException`` 的實例同時保留回溯。一旦被" +"引發,目前的 frame 會被加進 ``OtherException`` 的回溯,就像原來 " +"``SomeException`` 的回溯會發生的一樣,我們允許它被傳遞給呼叫者: ::" #: ../../library/exceptions.rst:143 msgid "" "A writable field that holds the :ref:`traceback object ` " "associated with this exception. See also: :ref:`raise`." msgstr "" +"可寫入的欄位,儲存關聯到該例外的\\ :ref:`回溯物件 `。也可" +"以參考 :ref:`raise`。" #: ../../library/exceptions.rst:149 msgid "" @@ -187,18 +241,24 @@ msgid "" "standard traceback after the exception string. A :exc:`TypeError` is raised " "if ``note`` is not a string." msgstr "" +"新增字串 ``note`` 到例外的備註,在標準的回溯裡,備註出現在例外字串的後面。如" +"果 ``note`` 不是字串則引發 :exc:`TypeError`。" #: ../../library/exceptions.rst:157 msgid "" "A list of the notes of this exception, which were added with :meth:" "`add_note`. This attribute is created when :meth:`add_note` is called." msgstr "" +"該例外的備註串列,使用 :meth:`add_note` 來新增。此屬性在 :meth:`add_note` 被" +"呼叫的時候建立。" #: ../../library/exceptions.rst:165 msgid "" "All built-in, non-system-exiting exceptions are derived from this class. " "All user-defined exceptions should also be derived from this class." msgstr "" +"所有內建、非系統退出 (non-system-exiting) 的例外都衍生自此類別。所有使用者定" +"義的例外應該也要衍生自此類別。" #: ../../library/exceptions.rst:171 msgid "" @@ -206,12 +266,16 @@ msgid "" "arithmetic errors: :exc:`OverflowError`, :exc:`ZeroDivisionError`, :exc:" "`FloatingPointError`." msgstr "" +"各種運算錯誤所引發的那些內建例外::exc:`OverflowError`、:exc:" +"`ZeroDivisionError`、:exc:`FloatingPointError` 的基底類別。" #: ../../library/exceptions.rst:178 msgid "" "Raised when a :ref:`buffer ` related operation cannot be " "performed." msgstr "" +"當\\ :ref:`緩衝 (buffer) ` 相關的操作無法被執行時會引發此例" +"外。" #: ../../library/exceptions.rst:184 msgid "" @@ -219,18 +283,20 @@ msgid "" "on a mapping or sequence is invalid: :exc:`IndexError`, :exc:`KeyError`. " "This can be raised directly by :func:`codecs.lookup`." msgstr "" +"當使用在對映或序列上的鍵或索引是無效的時候所引發的例外::exc:`IndexError`、:" +"exc:`KeyError` 的基底類別。這可以被 :func:`codecs.lookup` 直接引發。" #: ../../library/exceptions.rst:190 msgid "Concrete exceptions" -msgstr "" +msgstr "實體例外" #: ../../library/exceptions.rst:192 msgid "The following exceptions are the exceptions that are usually raised." -msgstr "" +msgstr "以下的例外是通常會被引發的例外。" #: ../../library/exceptions.rst:198 msgid "Raised when an :keyword:`assert` statement fails." -msgstr "" +msgstr "當 :keyword:`assert` 陳述式失敗的時候被引發。" #: ../../library/exceptions.rst:203 msgid "" @@ -238,6 +304,8 @@ msgid "" "assignment fails. (When an object does not support attribute references or " "attribute assignments at all, :exc:`TypeError` is raised.)" msgstr "" +"當屬性參照(參考 :ref:`attribute-references`)或賦值失敗的時候被引發。(當物" +"件根本不支援屬性參照或屬性賦值的時候,:exc:`TypeError` 會被引發。)" #: ../../library/exceptions.rst:207 msgid "" @@ -246,6 +314,9 @@ msgid "" "attribute that was attempted to be accessed and the object that was accessed " "for said attribute, respectively." msgstr "" +":attr:`name` 和 :attr:`obj` 屬性可以使用建構函式的僅限關鍵字 (keyword-only) " +"引數來設定。當被設定的時候,它們分別代表被嘗試存取的屬性名稱以及被以該屬性存" +"取的物件。" #: ../../library/exceptions.rst:212 msgid "Added the :attr:`name` and :attr:`obj` attributes." @@ -257,10 +328,13 @@ msgid "" "without reading any data. (N.B.: the :meth:`io.IOBase.read` and :meth:`io." "IOBase.readline` methods return an empty string when they hit EOF.)" msgstr "" +"當 :func:`input` 函式在沒有讀到任何資料而到達檔案結尾 (end-of-file, EOF) 條件" +"的時候被引發。(注意::meth:`io.IOBase.read` 和 :meth:`io.IOBase.readline` 方" +"法當達到 EOF 時會回傳空字串。)" #: ../../library/exceptions.rst:224 msgid "Not currently used." -msgstr "" +msgstr "目前沒有被使用。" #: ../../library/exceptions.rst:229 msgid "" @@ -269,6 +343,9 @@ msgid "" "exc:`BaseException` instead of :exc:`Exception` since it is technically not " "an error." msgstr "" +"當 :term:`generator` 或 :term:`coroutine` 被關閉的時候被引發;參考 :meth:" +"`generator.close` 和 :meth:`coroutine.close`。此例外直接繼承自 :exc:" +"`BaseException` 而不是 :exc:`Exception`,因為技術上來說這不是一個錯誤。" #: ../../library/exceptions.rst:237 msgid "" @@ -276,20 +353,22 @@ msgid "" "module. Also raised when the \"from list\" in ``from ... import`` has a " "name that cannot be found." msgstr "" +"當 :keyword:`import` 陳述式嘗試載入模組遇到問題的時候會被引發。當 ``from … " +"import`` 裡的 “from list” 包含找不到的名稱時也會被引發。" #: ../../library/exceptions.rst:241 msgid "" "The optional *name* and *path* keyword-only arguments set the corresponding " "attributes:" -msgstr "" +msgstr "可選的僅限關鍵字引數 *name* 和 *path* 設定對應的屬性:" #: ../../library/exceptions.rst:246 msgid "The name of the module that was attempted to be imported." -msgstr "" +msgstr "嘗試引入 (import) 的模組名稱。" #: ../../library/exceptions.rst:250 msgid "The path to any file which triggered the exception." -msgstr "" +msgstr "觸發此例外的任何檔案的路徑。" #: ../../library/exceptions.rst:252 msgid "Added the :attr:`name` and :attr:`path` attributes." @@ -301,6 +380,8 @@ msgid "" "module could not be located. It is also raised when ``None`` is found in :" "data:`sys.modules`." msgstr "" +":exc:`ImportError` 的子類別,當模組不能被定位的時候會被 :keyword:`import` 所" +"引發。當在 :data:`sys.modules` 裡找到 ``None`` 時也會被引發。" #: ../../library/exceptions.rst:266 msgid "" @@ -308,12 +389,14 @@ msgid "" "silently truncated to fall in the allowed range; if an index is not an " "integer, :exc:`TypeError` is raised.)" msgstr "" +"當序列的索引超出範圍的時候會被引發。(切片索引 (slice indices) 會默默地被截短" +"使其能落在允許的範圍內;如果索引不是整數,:exc:`TypeError` 會被引發。)" #: ../../library/exceptions.rst:275 msgid "" "Raised when a mapping (dictionary) key is not found in the set of existing " "keys." -msgstr "" +msgstr "當對映(字典)的鍵無法在已存在的鍵的集合中被找到時會被引發。" #: ../../library/exceptions.rst:282 msgid "" @@ -323,6 +406,10 @@ msgid "" "accidentally caught by code that catches :exc:`Exception` and thus prevent " "the interpreter from exiting." msgstr "" +"當使用者輸入中斷鍵 (interrupt key)(一般來說是 :kbd:`Control-C` 或 :kbd:" +"`Delete`)時會被引發。在執行過程中,會定期檢查是否產生中斷。此例外繼承自 :" +"exc:`BaseException` 以防止意外地被捕捉 :exc:`Exception` 的程式碼所捕捉,而因" +"此讓直譯器無法結束。" #: ../../library/exceptions.rst:290 msgid "" @@ -332,6 +419,10 @@ msgid "" "allow :exc:`KeyboardInterrupt` to end the program as quickly as possible or " "avoid raising it entirely. (See :ref:`handlers-and-exceptions`.)" msgstr "" +"捕捉 :exc:`KeyboardInterrupt` 需要特殊的考量。因為它可以在無法預期的時間點被" +"引發,可能在某些情況下讓正在跑的程式處在一個不一致的狀態。一般來說最好讓 :" +"exc:`KeyboardInterrupt` 越快結束程式越好,或者完全避免引發它。(參考 :ref:" +"`handlers-and-exceptions`。)" #: ../../library/exceptions.rst:300 msgid "" @@ -343,6 +434,11 @@ msgid "" "recover from this situation; it nevertheless raises an exception so that a " "stack traceback can be printed, in case a run-away program was the cause." msgstr "" +"當一個操作用光了記憶體但情況還可能被修復 (rescued)(透過刪除一些物件)的時候" +"被引發。關聯的值是一個字串,表示什麼類型的(內部)操作用光了記憶體。需注意的" +"是因為底層的記憶體管理架構(C 的 :c:func:`malloc` 函式),直譯器可能無法總是" +"完整地從該情況中修復;僅管如此,它還是引發例外以讓堆疊回溯可以被印出,以防原" +"因出在失控的程式。" #: ../../library/exceptions.rst:311 msgid "" @@ -350,6 +446,8 @@ msgid "" "unqualified names. The associated value is an error message that includes " "the name that could not be found." msgstr "" +"當找不到本地或全域的名稱時會被引發。這只應用在不合格的名稱 (unqualified " +"name) 上。關聯的值是一個錯誤訊息,包含那個無法被找到的名稱。" #: ../../library/exceptions.rst:315 msgid "" @@ -357,6 +455,8 @@ msgid "" "constructor. When set it represent the name of the variable that was " "attempted to be accessed." msgstr "" +":attr:`name` 屬性可以使用僅限關鍵字引數來設定到建構函式。當被設定的時候它代表" +"被嘗試存取的變數名稱。" #: ../../library/exceptions.rst:319 msgid "Added the :attr:`name` attribute." @@ -1000,7 +1100,7 @@ msgstr "" #: ../../library/exceptions.rst:880 msgid "See :ref:`io-encoding-warning` for details." -msgstr "細節請見 :ref:`io-encoding-warning`\\ 。" +msgstr "細節請見 :ref:`io-encoding-warning`。" #: ../../library/exceptions.rst:887 msgid "" @@ -1131,11 +1231,11 @@ msgstr "" #: ../../library/exceptions.rst:1031 msgid "Exception hierarchy" -msgstr "" +msgstr "例外階層" #: ../../library/exceptions.rst:1033 msgid "The class hierarchy for built-in exceptions is:" -msgstr "" +msgstr "內建例外的類別階層如下:" #: ../../library/exceptions.rst:6 ../../library/exceptions.rst:17 #: ../../library/exceptions.rst:196