Sau đây là từ mã nguồn django (Django-1.41/django/utils/encoding.py
);Tôi bị nhầm lẫn bởi mã này
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])
Câu hỏi của tôi là: Trong trường hợp này s
là trường hợp ngoại lệ?
khi s là một thể hiện của Ngoại lệ và s không có thuộc tính str hoặc repr. Tình trạng này xảy ra hơn. Thê nay đung không?
Tôi có thể viết 'tăng "a_string" 'bằng Python? –
Đối số duy nhất để tăng chỉ ra ngoại lệ được nêu ra. Đây phải là một trường hợp ngoại lệ hoặc một lớp ngoại lệ (một lớp xuất phát từ Ngoại lệ). – Yejing