For example, here is some code from django.templates.loader.app_directories.py.[1]
try:
yield safe_join(template_dir, template_name)
except UnicodeDecodeError:
# The template dir name was a bytestring that wasn't valid UTF-8.
raise
If you catch an exception just to re raise it, what purpose does it serve?
[1] http://code.djangoproject.com/browser/django/trunk/django/template/loaders/app_directories.py
In the code you linked to is another additional exception handler:
try:
yield safe_join(template_dir, template_name)
except UnicodeDecodeError:
# The template dir name was a bytestring that wasn't valid UTF-8.
raise
except ValueError:
# The joined path was located outside of template_dir.
pass
Since UnicodeDecodeError
is a subclass of ValueError
, the second exception handler would cause any UnicodeDecodeError
to be ignored. It looks like this would not be the intended effect and to avoid it the UnicodeDecodeError
is processed explicitly by the first handler. So with both handlers together a ValueError
is only ignored if it's not a UnicodeDecodeError
.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With