[XML-SIG] Specializing DOM exceptions

Martin v. Loewis martin@loewis.home.cs.tu-berlin.de
Wed, 6 Dec 2000 08:36:49 +0100


> Then, just as you would write:
> 
>         try:
>             bp = Breakpoint.bpbynumber[number]
>         except IndexError:
>             error message
> 
> You could write:
> 
>         try:
>             element = node.childNodes[number]
>         except IndexError:
>             error message

You certainly would - no matter how DOMExceptions work (*). The
question is whether users would prefer to write

   try:
     text1 = text.splitText(offs)
   except IndexError:
     error message

over

   try:
     text1 = text.splitText(offs)
   except IndexSizeErr:
     error message

Nobody would expect that splitText could possibly raise
IndexError. Nobody would guess that it could raise IndexSizeErr,
either - but at least you'd have the DOM documentation to tell you.

Regards,
Martin

(*) In DOM, childNodes does not have a []-operator; only a method
item(). Interestingly enough, that method is specified to return null
in case of an out-of-range index, not to raise INDEX_SIZE_ERR.