- Feature Articles
- CodeSOD
- Error'd
- Forums
-
Other Articles
- Random Article
- Other Series
- Alex's Soapbox
- Announcements
- Best of…
- Best of Email
- Best of the Sidebar
- Bring Your Own Code
- Coded Smorgasbord
- Mandatory Fun Day
- Off Topic
- Representative Line
- News Roundup
- Editor's Soapbox
- Software on the Rocks
- Souvenir Potpourri
- Sponsor Post
- Tales from the Interview
- The Daily WTF: Live
- Virtudyne
Admin
Universal Catch and Kill
Admin
If VB6 taught us anything, it's that if you don't see any error messages, then there must be no errors.
Admin
If you are using VB6 you have committed to the original error.
Admin
OTOH, if you are using .Net today but the code started as VB6 code and has been pastiche-modified ever since, you have committed "Normal USA-style 21st century devops".
Admin
not only catch and kill; it ensures the function returns null, which leaves responsibility for error handling to the caller - that's about as far as you can get from an error handling framework
Admin
in my experience the best strategy for handling errors is to have a single top-level error handler. Only catch specific errors lower down if you're expecting them and know how to recover
Admin
That method does consume a little bit of memory and CPU cycles. (Provided it's not optimized away at some point in the .NET pipeline.) I'd like to propose an alternative way to obtain the same result:
Admin
Well, it does do one thing: Provide a common class with a single spot to place a breakpoint.
Admin
Deferred execution with LINQ is great, but it can be misleading. There are two things here that make the ToList() necessary (although I won't make a judgment call on the correctness of the design). One is the error handling; errors are thrown where the query executes, which is not necessarily where it's written, so if you want to catch a LINQ error you have to actually run it. The other is the using - running a query on a disposed object is a very bad idea, so it needs to be executed inside the using scope.
However, my preference would still be to return an IEnumerable from the function even if it's internally a list, just for the sake of cleanliness.
Admin
Probably some KPI which gives some incentive if the number of bugs is below a random threshold.
And bugs which aren't logged don't count against the KPI.
Admin
This is simultaneously more and less valuable than it would have been if the error handling had been localised and correct.
More: It does allow commonality of code, and it does allow breakpointing on any error.
Less: It breakpoints on all errors, including the ones that aren't interesting, but also including the ones you didn't know where happening. (That might be a positive, of course.)
Admin
An error-mishandling framework.
Admin
I hope you know that this has been a feature of Visual Studio for at least twenty years. https://stackoverflow.com/questions/116896/visual-studio-how-to-break-on-handled-exceptions
Admin
That handler does something: it swallows exceptions silently.
That is rarely a good course of action.
Admin
Would you prefer if it spat them out and than complained and got angry you didn't warn it in time?
Admin
Don't modern .Net debugging systems allow you to break when an exception is raised?