Skip to content Skip to sidebar Skip to footer

Catching Any Doesnotexist Error

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 exce

Solution 1:

DoesNotExist exceptions are subclasses of django.core.exceptions.ObjectDoesNotExist:

from django.core.exceptions import ObjectDoesNotExist

try:
    # ...
except ObjectDoesNotExist as den:
    # handle exception

Post a Comment for "Catching Any Doesnotexist Error"