There are times when I really wonder exactly what I was thinking ...
-
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'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
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 -
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
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!
-
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 SubscriptionsI 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
-
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
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