Exceptions, Error Handling, Try/Catch, etc.

Having spent years developing with Visual Basic I am starting to realize that with the switch to C# and .NET, Exception handling is one core skill I still havent mastered. As a VB programmer I was always a bit anal about proper structure, defensive error handling, and seeking-out best practices. Since the best we had was On Error Goto style error handling, I adapted and "made do" with the tools at hand. However, I always lamented the need for a better tool for Error handling.

As a result, recently I have been spending alot of spare brain cycles on coming to terms with "correct" usage of .NET Exceptions and what (if any) best practices there are for Exception Handling in .NET.

Here are some of the topics I am exploring:

  • When to create Custom Exceptions?
  • Should I implement Logging within a custom Base Exception?
  • When to Try/Catch vs. allow exception to bubble?
  • When to Catch & reThrow a message?
  • When to Log vs. Throw exception?
  • When to return a result value vs. Throw an exception from a Function?

There are dozens of other topics I'm sure I'll stumble into, but I'm sure you get the gist. I enjoyed the recent post by Brad Abrams on Exceptions & Error Codes and found some answers, but many more questions.

Looks like its time to go do some research!

No Comments