usingException handling application block in n-tier

Topics: Exception Handling Application Block
Mar 11, 2011 at 7:21 AM

Hi,

We have decided to use the EHAP in our n-tier that is ui/wcf/bal and dal.

 

Can you please provide a sample code for the same.Any exception that occurs in DAl must be looged only once and throw

custom exception to the UI/also when passing  WCF service layer it should be thrown back has fault exception.

 

thanks

Mar 14, 2011 at 8:19 AM

Hi Santosh,

On the first scenario, you can create an Exception Handling Policy with a Post Handling Action of "ThrowNewException" and two handlers (Replace Handler and Logging Exception Handler). Let say your Policy is named "MyPolicy" and you have a method named "SomeMethods":

ExceptionManager manager = EnterpriseLibraryContainer.Current.GetInstance<ExceptionManager>();
manager.Process(SomeMethods, "MyPolicy");

If exception happens within SomeMethods, the exception will be replaced by the custom exception you have set in Replace Handler and at the same time, the exception will be logged.

On the second scenario, you can find a detailed explanation here about Exception Shielding in WCF. Hope this helps.