3.5 ProjectTracker Example

3.5 ProjectTracker Example

Old forum URL: forums.lhotka.net/forums/t/4717.aspx


SouthSpawn posted on Saturday, April 19, 2008

I notice that there aren't really many Try Catch blocks around the code.

Does anyone know if there is a reason for this?

Thanks,
Mark

RockfordLhotka replied on Monday, April 21, 2008

You should only catch an exception if you can do something about it.

"Do something" generally includes:

  1. Fix the problem (or notify the user there was an unfixable problem)
  2. Log the problem
  3. Add information about the problem by wrapping the exception with a more detailed exception

If you can't do one of these things, then don't catch the exception.

ProjectTracker could probably use a little more exception handling than it has at the UI layer. But at the data access and business layers there's really nothing to be done about exceptions, and so there's no reason to catch them.

In the DataPortal_XYZ methods it is critical that you do not catch exceptions, or if you do that you throw a new exception. Having an exception flow up from a DP_XZY method is how TransactionScope and EnterpriseServices know to roll back the failed transaction.

SouthSpawn replied on Monday, April 21, 2008

Thanks guys for your responses.
 
Mark

marklindell replied on Monday, April 21, 2008

Ask yourself this question: If you remove all the exception handling code in your application, will it continue to work correctly?  If is will not then you are not using exception handling correctly.

Copyright (c) Marimer LLC