If XmlException.SourceUri is read-only, what good is it?
Posted
by East of Nowhere
on Stack Overflow
See other posts from Stack Overflow
or by East of Nowhere
Published on 2010-05-14T17:01:58Z
Indexed on
2010/05/14
17:04 UTC
Read the original article
Hit count: 344
I have a couple places in my code where it throwing a new System.Xml.XmlException seems appropriate. I could just do
throw new XmlException("Your XML sucks go fix it then try again.");
But I think it's better to take advantage whenever possible of members particular to the exception class (otherwise ya might as well throw a plain ol' Exception
every time). SourceUri and LineNumber would be helpful, but they only have get
methods, there's no way I can assign a value to them! There's only 3 constructor overloads and none of them have parameters for those members either; I can only initialize Message
, nothing else.
There has got to be some way to populate those data members with values, otherwise why does XmlException bother with them?
I suppose I could make a new class that inherits XmlException and write a new constructor that initializes SourceUri etc. but still, there must be a way to just use XmlException. Right?
© Stack Overflow or respective owner