Pages

Showing posts with label custom. Show all posts
Showing posts with label custom. Show all posts

Tuesday, June 6, 2017

Difference Between ASP NET User Controls and Custom Controls

Difference Between ASP NET User Controls and Custom Controls


Read more »

Wednesday, April 19, 2017

Django Reminder Handling Custom Exceptions

Django Reminder Handling Custom Exceptions


In Django, if we try to get an object that does not exist, the DoesNotExist exception will be raised.

However, the following code does not work out of the box, albeit being the obvious solution to handle such exception:

try:
    img = Image.objects.get(pk = 42)
except DoesNotExist:
    print "Image Does Not Exist"

This is because the DoesNotExist exception is actually an attribute of an model object.

Therefore, we would need to use this exception express to handle it (so we dont have to import the error manually)

except Image.DoesNotExist:
    print "Image Does Not Exist"

To handle more than one possible exception, use the standard Python way to add more exception cases:

except (ValueError, Image.DoesNotExist):
    #do something.


Read more »