Hey everyone, I'm writing a project that does some communication with proprietary devices on a non-standard protocol, so I've written a custom exception class that extends Exception and has some additional useful parameters. However, when I raise an exception instantiated from my class, the pretty Django error page doesn't report any of the parameters. It's probably a stupid mistake I've made, but I can't figure it out.
Here's a snippet of my custom exception class (with additional, similar code removed for the sake of clarity): class ConnectionError(Exception): CONNECTION_REFUSED = 1 INVALID_DATA = 2 def __init__(self, type, buffer_name, *args, **kwargs): self.type = type self.buffer_name = buffer_name self.args = args def __str__(self): if self.type == ConnectionError.CONNECTION_REFUSED: return 'Connection refused for %s' % self.buffer_name elif self.type == ConnectionError.INVALID_DATA: # The first arg in self.args is the string we got back from the device return 'Invalid data received for %s: "%s"' % (self.buffer_name, self.args[0]) else: return "Unknown connection error" In a view, if I try raise ConnectionError(ConnectionError.CONNECTION_REFUSED, "mainbuf") then the pretty Django error page just says ConnectionError at /page/ Request Method: GET without any specifics. Ideally, I'd like to see the custom "Connection refused for %s" string that I wrote. At the same time, if I try raise ConnectionError(ConnectionError.INVALID_DATA, "mainbuf", "BADDATA") then the Django error page says ConnectionError at /page/ BADDATA Request Method: GET In the second case, Django catches the last argument, but not the first. But in both cases, it doesn't read my custom string message. Is there any way to display custom error strings, or am I doing something completely wrong? Thanks a ton! Nick --~--~---------~--~----~------------~-------~--~----~ You received this message because you are subscribed to the Google Groups "Django users" group. To post to this group, send email to django-users@googlegroups.com To unsubscribe from this group, send email to django-users+unsubscr...@googlegroups.com For more options, visit this group at http://groups.google.com/group/django-users?hl=en -~----------~----~----~----~------~----~------~--~---