Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • World
  • Users
  • Groups
Skins
  • Light
  • Cerulean
  • Cosmo
  • Flatly
  • Journal
  • Litera
  • Lumen
  • Lux
  • Materia
  • Minty
  • Morph
  • Pulse
  • Sandstone
  • Simplex
  • Sketchy
  • Spacelab
  • United
  • Yeti
  • Zephyr
  • Dark
  • Cyborg
  • Darkly
  • Quartz
  • Slate
  • Solar
  • Superhero
  • Vapor

  • Default (No Skin)
  • No Skin
Collapse
Code Project
  1. Home
  2. Other Discussions
  3. The Weird and The Wonderful
  4. There are times when I really wonder exactly what I was thinking ...

There are times when I really wonder exactly what I was thinking ...

Scheduled Pinned Locked Moved The Weird and The Wonderful
csharpjsonhelp
5 Posts 5 Posters 25 Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • OriginalGriffO Offline
    OriginalGriffO Offline
    OriginalGriff
    wrote on last edited by
    #1

    I'm changing ISP's in a week or so, so I resurrected an old app I wrote to monitor my ISP and tell me when it changed. And it didn't work any more, because the IP Geolocation service I was using has changed and needs an API signup instead of presenting the data as CSV. So, I thought I'd re-write it using HtmlAgilityPack. But it was odd that I got no error message in the original code ... until I spotted this:

        private void FillInDetails(string host)
            {
            Timestamp = DateTime.Now;
            IPAddress addr = IPAddress.None;
            try
                {
                using (WebClient wc = new WebClient())
                    {
                    if (string.IsNullOrWhiteSpace(host))
                        {
                        host = "http://freegeoip.net/csv";
                        }
                    else
                        {
                        host = string.Format("http://freegeoip.net/csv{0}{1}", "/", host);
                        }
                    string data = wc.DownloadString(host);
                    string\[\] sections = BreakCSVLine(data);
                    if (sections.Length != freegeoipDataSectionsCount) throw new ArgumentException("Data returned from FreeGeoIP has changed format!");
                    addr = IPAddress.Parse(sections\[freegeoipDataAddress\]);
                    CountryCode = sections\[freegeoipDataCountryCode\];
                    Country = sections\[freegeoipDataCountry\];
                    RegionCode = sections\[freegeoipDataRegionCode\];
                    Region = sections\[freegeoipDataRegion\];
                    City = sections\[freegeoipDataCity\];
                    Zipcode = sections\[freegeoipDataZipcode\];
                    TimeZone = sections\[freegeoipDataTimeZone\];
                    Area = sections\[freegeoipDataArea\];
                    float lat = float.Parse(sections\[freegeoipDataLatitude\]);
                    float lon = float.Parse(sections\[freegeoipDataLongditude\]);
                    LatLong = new PointF(lon, lat);
                    }
                }
            catch (Exception)
                {
                // Ignore errors (it probably means the router is down...)
                }
            Address = addr;
            }
    

    So I carefully create my own exception to tell me why it's not working ... and then explicitly ignore it. I do wonder about past-me's thought processes sometimes ... :sigh:

    "I

    "I have no idea what I did, but I'm taking full credit for it." - ThisOldTony
    "Common sense is so rare these days, it should be classified as a super power" - Random T-shirt

    M B D 3 Replies Last reply
    0
    • OriginalGriffO OriginalGriff

      I'm changing ISP's in a week or so, so I resurrected an old app I wrote to monitor my ISP and tell me when it changed. And it didn't work any more, because the IP Geolocation service I was using has changed and needs an API signup instead of presenting the data as CSV. So, I thought I'd re-write it using HtmlAgilityPack. But it was odd that I got no error message in the original code ... until I spotted this:

          private void FillInDetails(string host)
              {
              Timestamp = DateTime.Now;
              IPAddress addr = IPAddress.None;
              try
                  {
                  using (WebClient wc = new WebClient())
                      {
                      if (string.IsNullOrWhiteSpace(host))
                          {
                          host = "http://freegeoip.net/csv";
                          }
                      else
                          {
                          host = string.Format("http://freegeoip.net/csv{0}{1}", "/", host);
                          }
                      string data = wc.DownloadString(host);
                      string\[\] sections = BreakCSVLine(data);
                      if (sections.Length != freegeoipDataSectionsCount) throw new ArgumentException("Data returned from FreeGeoIP has changed format!");
                      addr = IPAddress.Parse(sections\[freegeoipDataAddress\]);
                      CountryCode = sections\[freegeoipDataCountryCode\];
                      Country = sections\[freegeoipDataCountry\];
                      RegionCode = sections\[freegeoipDataRegionCode\];
                      Region = sections\[freegeoipDataRegion\];
                      City = sections\[freegeoipDataCity\];
                      Zipcode = sections\[freegeoipDataZipcode\];
                      TimeZone = sections\[freegeoipDataTimeZone\];
                      Area = sections\[freegeoipDataArea\];
                      float lat = float.Parse(sections\[freegeoipDataLatitude\]);
                      float lon = float.Parse(sections\[freegeoipDataLongditude\]);
                      LatLong = new PointF(lon, lat);
                      }
                  }
              catch (Exception)
                  {
                  // Ignore errors (it probably means the router is down...)
                  }
              Address = addr;
              }
      

      So I carefully create my own exception to tell me why it's not working ... and then explicitly ignore it. I do wonder about past-me's thought processes sometimes ... :sigh:

      "I

      M Offline
      M Offline
      Marc Clifton
      wrote on last edited by
      #2

      Exception handling/reporting is something I've never figured out how to do well, especially when writing a web application. The back-end throws an exception. What do you do? Log it somewhere nobody ever looks, least of all me? Do you report it to the front-end? The front-end has to deal with the back-end exception. What do you do? Display an obtuse message to the user? The front-end itself generates an exception. Is it even caught? What do you do? Another obtuse message? Or an API endpoint that it calls to log it on the server in a log that no one, least of all me, ever looks at? I've decided to take a rather drastic approach to very specific problems (like a failure to update an audit table) - I email myself the exception and filter it in Outlook into specific folders. I find it a lot more effective in knowing about the exception and to fix it. :laugh:

      Latest Articles:
      Client-Side Type-Based Publisher/Subscriber, Exploring Synchronous, "Event-ed", and Worker Thread Subscriptions

      Sander RosselS 1 Reply Last reply
      0
      • OriginalGriffO OriginalGriff

        I'm changing ISP's in a week or so, so I resurrected an old app I wrote to monitor my ISP and tell me when it changed. And it didn't work any more, because the IP Geolocation service I was using has changed and needs an API signup instead of presenting the data as CSV. So, I thought I'd re-write it using HtmlAgilityPack. But it was odd that I got no error message in the original code ... until I spotted this:

            private void FillInDetails(string host)
                {
                Timestamp = DateTime.Now;
                IPAddress addr = IPAddress.None;
                try
                    {
                    using (WebClient wc = new WebClient())
                        {
                        if (string.IsNullOrWhiteSpace(host))
                            {
                            host = "http://freegeoip.net/csv";
                            }
                        else
                            {
                            host = string.Format("http://freegeoip.net/csv{0}{1}", "/", host);
                            }
                        string data = wc.DownloadString(host);
                        string\[\] sections = BreakCSVLine(data);
                        if (sections.Length != freegeoipDataSectionsCount) throw new ArgumentException("Data returned from FreeGeoIP has changed format!");
                        addr = IPAddress.Parse(sections\[freegeoipDataAddress\]);
                        CountryCode = sections\[freegeoipDataCountryCode\];
                        Country = sections\[freegeoipDataCountry\];
                        RegionCode = sections\[freegeoipDataRegionCode\];
                        Region = sections\[freegeoipDataRegion\];
                        City = sections\[freegeoipDataCity\];
                        Zipcode = sections\[freegeoipDataZipcode\];
                        TimeZone = sections\[freegeoipDataTimeZone\];
                        Area = sections\[freegeoipDataArea\];
                        float lat = float.Parse(sections\[freegeoipDataLatitude\]);
                        float lon = float.Parse(sections\[freegeoipDataLongditude\]);
                        LatLong = new PointF(lon, lat);
                        }
                    }
                catch (Exception)
                    {
                    // Ignore errors (it probably means the router is down...)
                    }
                Address = addr;
                }
        

        So I carefully create my own exception to tell me why it's not working ... and then explicitly ignore it. I do wonder about past-me's thought processes sometimes ... :sigh:

        "I

        B Offline
        B Offline
        Bernhard Hiller
        wrote on last edited by
        #3

        Beyond that Exception, what's that:

        OriginalGriff wrote:

        host = string.Format("http://freegeoip.net/csv{0}{1}", "/", host);

        Why do you need a parameter for the constant value of "/"? My diagnosis: A severe case of hypocaffeinaemia.

        Oh sanctissimi Wilhelmus, Theodorus, et Fredericus!

        1 Reply Last reply
        0
        • M Marc Clifton

          Exception handling/reporting is something I've never figured out how to do well, especially when writing a web application. The back-end throws an exception. What do you do? Log it somewhere nobody ever looks, least of all me? Do you report it to the front-end? The front-end has to deal with the back-end exception. What do you do? Display an obtuse message to the user? The front-end itself generates an exception. Is it even caught? What do you do? Another obtuse message? Or an API endpoint that it calls to log it on the server in a log that no one, least of all me, ever looks at? I've decided to take a rather drastic approach to very specific problems (like a failure to update an audit table) - I email myself the exception and filter it in Outlook into specific folders. I find it a lot more effective in knowing about the exception and to fix it. :laugh:

          Latest Articles:
          Client-Side Type-Based Publisher/Subscriber, Exploring Synchronous, "Event-ed", and Worker Thread Subscriptions

          Sander RosselS Offline
          Sander RosselS Offline
          Sander Rossel
          wrote on last edited by
          #4

          I feel your pain! Been struggling with this myself. I always make sure my users know something went wrong. Like really wrong. They should get an exception and not be able to continue. Preferably some "scary" message that sounds very technical. Very user unfriendly, but at least they'll call me so I can fix the issue instead of ignoring the error and continuing with potentially corrupt data (yes, that happened in the past) :laugh:

          Best, Sander Azure DevOps Succinctly (free eBook) Azure Serverless Succinctly (free eBook) Migrating Apps to the Cloud with Azure arrgh.js - Bringing LINQ to JavaScript

          1 Reply Last reply
          0
          • OriginalGriffO OriginalGriff

            I'm changing ISP's in a week or so, so I resurrected an old app I wrote to monitor my ISP and tell me when it changed. And it didn't work any more, because the IP Geolocation service I was using has changed and needs an API signup instead of presenting the data as CSV. So, I thought I'd re-write it using HtmlAgilityPack. But it was odd that I got no error message in the original code ... until I spotted this:

                private void FillInDetails(string host)
                    {
                    Timestamp = DateTime.Now;
                    IPAddress addr = IPAddress.None;
                    try
                        {
                        using (WebClient wc = new WebClient())
                            {
                            if (string.IsNullOrWhiteSpace(host))
                                {
                                host = "http://freegeoip.net/csv";
                                }
                            else
                                {
                                host = string.Format("http://freegeoip.net/csv{0}{1}", "/", host);
                                }
                            string data = wc.DownloadString(host);
                            string\[\] sections = BreakCSVLine(data);
                            if (sections.Length != freegeoipDataSectionsCount) throw new ArgumentException("Data returned from FreeGeoIP has changed format!");
                            addr = IPAddress.Parse(sections\[freegeoipDataAddress\]);
                            CountryCode = sections\[freegeoipDataCountryCode\];
                            Country = sections\[freegeoipDataCountry\];
                            RegionCode = sections\[freegeoipDataRegionCode\];
                            Region = sections\[freegeoipDataRegion\];
                            City = sections\[freegeoipDataCity\];
                            Zipcode = sections\[freegeoipDataZipcode\];
                            TimeZone = sections\[freegeoipDataTimeZone\];
                            Area = sections\[freegeoipDataArea\];
                            float lat = float.Parse(sections\[freegeoipDataLatitude\]);
                            float lon = float.Parse(sections\[freegeoipDataLongditude\]);
                            LatLong = new PointF(lon, lat);
                            }
                        }
                    catch (Exception)
                        {
                        // Ignore errors (it probably means the router is down...)
                        }
                    Address = addr;
                    }
            

            So I carefully create my own exception to tell me why it's not working ... and then explicitly ignore it. I do wonder about past-me's thought processes sometimes ... :sigh:

            "I

            D Offline
            D Offline
            Dan Neely
            wrote on last edited by
            #5

            If it was my terrible code, the empty `Catch()` block would've been a helpful breakpoint holder while I was debugging the initial implementation. It may also have had code to handle a case that I subsequently made impossible.

            Did you ever see history portrayed as an old man with a wise brow and pulseless heart, weighing all things in the balance of reason? Is not rather the genius of history like an eternal, imploring maiden, full of fire, with a burning heart and flaming soul, humanly warm and humanly beautiful? --Zachris Topelius

            1 Reply Last reply
            0
            Reply
            • Reply as topic
            Log in to reply
            • Oldest to Newest
            • Newest to Oldest
            • Most Votes


            • Login

            • Don't have an account? Register

            • Login or register to search.
            • First post
              Last post
            0
            • Categories
            • Recent
            • Tags
            • Popular
            • World
            • Users
            • Groups