I am using Django 1.7. Normally you can catch DoesNotExist exception over your model like;
try:
...
except model.DoesNotExist, den:
...
I want to catch any DoesNotExist exception. I really don't want to care about its model. Actually, I really don't know which model DoesNotExist is passing through the code piece either. I mean, I am not able to know the model.
So I have to catch any DoesNotExist error somehow.
Is there a way to catch any DoesNotExist error in Django?
DoesNotExist exceptions are subclasses of django.core.exceptions.ObjectDoesNotExist:
from django.core.exceptions import ObjectDoesNotExist
try:
# ...
except ObjectDoesNotExist as den:
# handle exception
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