यह निम्नलिखित 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
अपवाद का एक उदाहरण होगा?
जब एस अपवाद का एक उदाहरण है, और उसके पास न तो str या repr विशेषता है। इस स्थिति की तुलना में। क्या यह सही है?
मैं अजगर में लिख सकते हैं 'उठाने" a_string "': एक पुल अनुरोध खोलने के बाद, इस कोड को अब Django स्रोत से हटा दिया गया है? –
उठाने का एकमात्र तर्क उठाए जाने के अपवाद को इंगित करता है। यह या तो एक अपवाद उदाहरण या अपवाद वर्ग (एक वर्ग जो अपवाद से निकला है) होना चाहिए। – Yejing