以下是來自django的源代碼(Django-1.41/django/utils/encoding.py
);我對這段代碼感到困惑
try:
s = unicode(str(s), encoding, errors)
except UnicodeEncodeError:
if not isinstance(s, Exception):
raise
# If we get to here, the caller has passed in an Exception
# subclass populated with non-ASCII data without special
# handling to display as a string. We need to handle this
# without raising a further exception. We do an
# approximation to what the Exception's standard str()
# output should be.
s = u' '.join([force_unicode(arg, encoding, strings_only,
errors) for arg in s])
我的問題是:在這種情況下s
會是異常的一個實例嗎?
當s是Exception的一個實例時,s不具有str或repr屬性。比這種情況發生。這是正確的嗎?
我可以寫'養 「在此處a_string」'在Python: 打開拉請求後,該代碼現在已經從Django的源刪除? –
引發的唯一參數表示要引發的異常。這必須是異常實例或異常類(從Exception派生的類)。 – Yejing