0

I have following problem: My tool checks every 6min a RSS-Feed. This works perfectly but the server on which the RSS-Feed is hosted, is sometimes not available for some seconds. The "check"-part runs 24/7. So sometimes it throws an error: 500 - internal server error and therefore my tool sometimes stops working.

How can I catch this? (I don't need to recheck if it failed. Just need to catch that error so that the tool continues running)

This is the code, I use:

    // RSS WORKARONUD
    String[,] rssData = null;

    private String[,] getRssData(String channel)
    {
        System.Net.ServicePointManager.SecurityProtocol = SecurityProtocolType.Tls | SecurityProtocolType.Tls12;
        System.Net.WebRequest myRequest = System.Net.WebRequest.Create(channel);
        System.Net.WebResponse myResponse = myRequest.GetResponse();


        System.IO.Stream rssStream = myResponse.GetResponseStream();
        System.Xml.XmlDocument rssDoc = new System.Xml.XmlDocument();

        rssDoc.Load(rssStream);

        System.Xml.XmlNodeList rssItems = rssDoc.SelectNodes("rss /channel/item");

        //Matrix, 100 rows , 3 colums
        String[,] tempRssData = new String[100, 3];
RedP1ll
  • 3
  • 4

1 Answers1

0
System.Net.ServicePointManager.SecurityProtocol = SecurityProtocolType.Tls | SecurityProtocolType.Tls12;
        System.Net.WebRequest myRequest = System.Net.WebRequest.Create(channel);
        System.Net.WebResponse myResponse = myRequest.GetResponse();

try
{
        System.IO.Stream rssStream = myResponse.GetResponseStream();
        System.Xml.XmlDocument rssDoc = new System.Xml.XmlDocument();

        rssDoc.Load(rssStream);

        System.Xml.XmlNodeList rssItems = rssDoc.SelectNodes("rss /channel/item");
  //Matrix, 100 rows , 3 colums
        String[,] tempRssData = new String[100, 3];
}
Catch(Exception ex)
{
}
Prateek Shrivastava
  • 1,877
  • 1
  • 10
  • 17
  • Thank you! Should work now. I wrapped it around the wrong code part :/ I returned "null" (return null; ) if it failes. Is this correct? – RedP1ll Mar 19 '18 at 09:36
  • Returning Null would be good or not depends on the calling code. If Null has been handled there appropriately - then why not. – Prateek Shrivastava Mar 20 '18 at 02:12