Brandon Lewis

Brandon Lewis

  • NA
  • 527
  • 126k

Exception Handling Etiquette

Jan 18 2008 4:05 PM
I asked this question awhile back on CodeGuru.com but I want to ask it here too since this forum is more centered on .NET programming.

I have a few applications that contains classes containing classes, containing classes and so on, that are fairly complex little widgets. As far as error handling goes, I usually handle and log the errors to an exceptions.log file in the most descendant classes. From there, I bubble the exceptions up to the UI via try-catch blocks until they reach the UI (or the end of the stack for seperate threads) and there I put my custom and friendly message into a message box for the user to see.

Im looking to change course a bit and perhaps throw custom exceptions, or catch them at the most descendant level, build a custom message, and rethrow the custom message, then on the UI level, catch it and display the message, ultimately eliminating all of the middle man try-catch blocks contained in all of the levels of classes between the most descendant classes and the UI, where the user sees the error message.

I guess what Im getting as is, how do you guys handle your exceptions? Im just trying to explore different ways of doing it. Theres so many ways you can handle them, and I think it would do some good for us to talk about the different ways we handle exceptions in larger applications (mine being almost 10k lines and spreading across 5 linked libraries, lol).

Answers (2)