4 ms·
imho the author paints a very accurate picture of c#. exception handling remains a mystery to many programmers and is a constant source of errors. error handli
by verinus 11y ago
imho the author paints a very accurate picture of c#. exception handling remains a mystery to many programmers and is a constant source of errors.
error handling in general is hard to do; to have good, what i would call, "error partitioning"- catching errors/exceptions where they can be fixed is difficult- regardless of exceptions.
perhaps you got your error handling right and don't need more catch clauses, but if I was you I would investigate :)
- WorldWideWayne 11y agoBad programmers write bad code in general, so basing your opinion of C#'s error handling system on their use of it seems unwarranted. Exception handling does not remain a mystery to many programmers, just many bad programmers. Aside from that, the author is a contributor to Rust so I suspect there could be some small amount of bias here. > ...catching errors/exceptions where they can be fixed is difficult... What's difficult? When your program is about to do something like say open a file - if you don't want an exception to be raised from that code, you wrap that code in a try...catch. In the catch block, you take corrective action. The very simple bottom line with error handling in .NET apps is that you handle/log/notify the user at process and thread entry-points like main and AppDomain.UnhandledException. Other than that, you use a try...catch block.
- vitalyd 11y agoError handling is one of the harder aspects of software engineering, IMHO. For starters, those code paths are less tested than others. See this, for example: https://www.usenix.org/system/files/conference/osdi14/osdi14-paper-yuan.pdf https://www.usenix.org/system/files/conference/osdi14/osdi14...
- kibwen 11y agoIt's a bit of a reach to sling accusations of bias. The Rust project makes it trivial for people to contribute, so anyone with even a passing interest in the language can become a "contributor to Rust" in seconds. If you try and disqualify all of the 1,000+ Rust contributors from writing blog posts about the language, then you most likely also disqualify everyone qualified to write about the language from writing about the language. :P
- WorldWideWayne 11y agoI didn't sling an accusation, I said "I suspect there could be some small amount of bias". If I were accusing, I would have said "this person is biased.". Despite what you say, I still think the suspicion is valid.
- kibwen 11y agoThat's fair, although I suspect that your suspicion of bias may be biased due to your usage of C#. :)
- WorldWideWayne 11y agoThe irony here is that people on HN do judge you if you live mostly in the C#/.NET world, but you're arguing against my suspicion of people who contribute to Mozilla. Do you think it's a far stretch to say that people who actively use open source languages and libraries and contribute to Mozilla projects are much more likely to be biased against anything that Microsoft does?
- kibwen 11y agoYou're still leaping to conclusions, you're just trying to justify it behind a veneer of persecution. I'm a Rust contributor and I think C# is a fantastic language; it's my dream to tempt Anders Hejlsberg away to Rust. :P I'm also typing this from a Windows 7 netbook, my sole computer, though I'm looking to upgrade to a Surface once Windows 10 is here. We have several former Microsoft employees in our ranks and one of our core contributors is currently interning at Microsoft. It is possible to be critical without there being a hidden agenda!
- WorldWideWayne 11y agoIt is possible, just not probable. You're an outlier.
- danbruc 11y agopublic static UInt32 CheckNextVersion([...]) { Contract.Requires(previousVersions != null); Contract.Requires(versionString != null); UInt32 version; if (!UInt32.TryParse(versionString, out version)) throw new ParseException(); var min = previousVersions.Cast<UInt32?>().Min(); if (min == 0) throw new NewReleaseImpossibleException(); if (version >= min) throw new InvalidVersionException(); return version; } I still wouldn't use this code in production but all the exception handling in the article is completely unnecessary and even throwing those exceptions in the error cases is a design decision. You could as well create your own Result<T> type either containing a value of type T or an error message and return that. Obviously the more support by the language and the compiler you get the better, but you can still do it even without. public static Result<UInt32> CheckNextVersion([...]) { Contract.Requires(previousVersions != null); Contract.Requires(versionString != null); UInt32 version; if (!UInt32.TryParse(versionString, out version)) { return Result.Error<UInt32>("Bad version string."); } else { var minimumPreviousVersion = previousVersions.Minimum(); if (minimumPreviousVersion == 0) { return Result.Error<UInt32>("New release impossible."); } else if (version >= minimumPreviousVersion) { return Result.Error<UInt32>("Invalid version."); } else { return Result.Success(version); } }