[XML-SIG] Specializing DOM exceptions
Martin v. Loewis
martin@loewis.home.cs.tu-berlin.de
Tue, 5 Dec 2000 23:01:05 +0100
> My concern is that Python already has an IndexError and it is raised
> "naturally" (and efficiently) in a lot of places in minidom. At one
> point we had talked about formalizing a mechanism where Python
> exceptions stand for DOM exceptions.
>
> So IndexSizeErr could be a subclass of Python's IndexError. Python
> "clients" could check for IndexError as they would in any other Python
> code. Those that want to treat the DOM stuff specially could do so. This
> would all be part of the Python-DOM mapping.
I don't see the value of this. When applications catch IndexError,
they normally do so to wrap a specific index access. In the Python
library, I found the following places where IndexError is caught:
try:
bp = Breakpoint.bpbynumber[number]
except IndexError:
return 'Breakpoint number (%d) out of range' % number
#############
try:
result.append(self[key])
except IndexError:
result.append(self.dict[key])
#############
try:
self.response = args[0]
except IndexError:
self.response = 'No response given'
...
I can't imagine a scenario where a DOM INDEX_SIZE_ERR and a Python
IndexError could likewise occur for a block of code, and would deserve
identical, specific treatment.
That said, if you think it is useful: go ahead and propose a specific
patch. It probably can't hurt.
Regards,
Martin