I'm working on obtaining RSS feeds like so:
SyndicationFeed rss = SyndicationFeed.Load(XmlReader.Create(textBox1.Text));
XmlReader.Create()
in this case can throw up to 4 exceptions related to things like the parameter being null, 404 error, etc.
Should I try to validate the Uri (make sure it's not null, 404, correct doctype, etc) before I call that line or should I just handle the exceptions? I know I've read numerous times on SO that exceptions should be used for truly exceptional circumstances and I agree this doesn't seem to meet that prerequisite but it seems easier to just handle the exceptions.
The Text
property of a checkbox is never null, so you can skip that one. Check manually all the cases that are simple and not related to the process like string being empty and Url being correct and leave more obscure XML-specific stuff to the validation inside Create
method. So the answer is to combine both.
Also, let me once again refer to a blog post by Eric Lippert about exceptions. In your case both vexing and exogenous exceptions can happen, so you should probably catch them. But make sure that boneheaded ones don't occur.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With