0

Which is prefer in what case in the concept of reuse predefined exception classes?

For example I was parsing a document using XmlReader and faced with inconsistent close tag:

<?xml version=""1.0"" encoding=""UTF-8""?>
<element1>
    <element2>
        some content
    </element3>
</element1>

What to throw?

It should be noted that this two exceptions do not inherit one another so should be caught separately.

SerG
  • 1,251
  • 4
  • 18
  • 37
  • Wouldn't `XmlReader` itself throw the exception? Why are you considering throwing it yourself? – Jon Skeet Aug 19 '14 at 09:17
  • @JonSkeet, XmlReader allows low level access to XML, so I can use it for handling a document node by node and make any decision by myself. – SerG Aug 19 '14 at 09:29
  • But this is invalid XML, isn't it? Or are you adding additional requirements *on top of* normal XML? – Jon Skeet Aug 19 '14 at 10:01
  • @JonSkeet Yes it's invalid XML, but XmlReader doesn't know that as operates by individual nodes, not elements. And yes I have additional requirements for such case. – SerG Aug 19 '14 at 10:14
  • It would really help if you'd give an example of such invalid XML. I'd expect `XmlReader` to pick up on it - it only gives *events* for individual nodes, but I'd expect it to have enough context to notice that (for example) you were closing a different tag to the one you opened. – Jon Skeet Aug 19 '14 at 10:31
  • 1
    (I've just validated that it *does* indeed do that.) – Jon Skeet Aug 19 '14 at 10:33

0 Answers0