What kind of error handling is this?
about .NET on 17/10/2008 - like it?
You’d be surprised the things that can be found during basic code reviews :) Once I found a pen I thought I’d lost … :) in all seriousness though, nothing drives me more crazy than seeing the following.
try { // some code } catch (Exception e) { throw e; }
I could scream! and actually it wouldn’t be the first time either. I don’t have a lot of patience for things like this.
If you aren’t sure what is wrong, let us take a closer look. For one, I came across this while actually hunting for a memory leak but I could never see an exception on any line except “throw e;” - because no matter what went wrong, the exception was caught and just thrown again and since the last line responsible is always the throw, I had to attach a debugger to find the real error.
The second problem is you haven’t actually accomplished anything, nada, zip, less than $2c of quality code here people - it doesn’t do anything. If you’re going to catch an error then DEAL with it.
I have seen some developers catch an error, log various details and then throw some kind of error again. Maybe there is a need for that but I doubt it can be justified very often. If something goes wrong you need to try fix the problem and continue normal operations so you users are unaware and if you can’t then fail gracefully.
Make sure too that you LOG errors - use any means necessary but just make sure the stack trace and some information about system state is recorded so you can fix fix fix :) - since its probably your fault it broke to start with.
And if you don’t have any error handling, get too it! Nothing could be worse than your users getting the yellow? screen of death :)
Here is something if you’re just beginning - I’ve always found these books pretty good for getting started, including some basics like the above.
![]()
Beginning Microsoft Visual C# 2008 (Wrox Beginning Guides)

No comments - not surprising really, but why not break the trend...