Das folgende ist aus dem Django-Quellcode (Django-1.41/django/utils/encoding.py
);Ich bin verwirrt durch diesen Code
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])
Meine Frage ist: In diesem Fall wird s
eine Instanz Ausnahme sein?
wenn s eine Instanz von Exception ist und s weder das Attribut str oder rep hat. Dann passiert diese Situation. Ist das richtig?
Kann ich schreiben 'raise "a_string"' in Python? –
Das einzige Argument zum Erhöhen gibt die Ausnahme an, die ausgelöst werden soll. Dies muss entweder eine Ausnahmeinstanz oder eine Ausnahmeklasse sein (eine Klasse, die von Exception abgeleitet ist). – Yejing