Here’s another example of someone working too hard …
Here, the developer is trying to only take action on a specific kind of exception. The trick here is that C# includes native support for this kind of thing. The (simpler) code that works as required is this:
The goal here is to only catch the exception you need, let the others propagate normally.
This kind of error seems to be common with developers with backgrounds involving tools (such as classic Visual Basic) where error handling much coarser than C#.
The key lesson to be learned here isn’t about exception handling, it is this: Habits shouldn’t always be carried forward with you from platform to platform - good practice in one may not be good practice in the next, especially if that practice was to work around limitations in the platform that may no longer exist.
Comments
blog comments powered by Disqus