What is the queue to the ExceptionCallHandler?

Topics: Exception Handling Application Block, Policy Injection Application Block
Jun 28, 2011 at 9:58 AM

Hi,

I want to log the running exception by the policy intercept. So I defined a custom call handler.

if there is exception after the getNext run it will log the exception, or   it will return the value.

But it will throw the exception direct and not to log the exception.

I think it must have some misunderstood for me. Can anyone give me some advices?

Here is my source code:

[ExceptionLogCallhandler("Save Product",1)]

public void Save(Product product)

{

    throw new Exception("Exception Test.")

}

 public IMethodReturn Invoke(IMethodInvocation input, GetNextHandlerDelegate getNext)      

 {            

         IMethodReturn methodReturn=getNext()(input, getNext);      

         // the exception will throw out direct and the follow code snippet will not be execute.    

        if (methodReturn.Exception != null)          

               {              

                     LogWriter logWrite = EnterpriseLibraryContainer.Current.GetInstance<LogWriter>();              

                     LogEntry log = new LogEntry();              

                     log.Title = Message;                

                     log.Message = methodReturn.Exception.Message + methodReturn.Exception.InnerException.Message;              

                     logWrite.Write(log);

                     throw new Exception("The service issue, please wait or connect to the system administrator.");          

                }          

               else          

              {              

                      return methodReturn;            

               }      

      }

 

Thanks.

David

Jun 28, 2011 at 10:55 AM
Edited Jun 28, 2011 at 11:59 AM

Hi,

The code you posted will log the error and return the value. The exception will not happen inside the call handler but to the calling method.

 

Noel Angelo Bolasoc
Global Technologies and Solutions
Avanade, Inc.
entlib.support@avanade.com

Jun 29, 2011 at 9:02 AM

Thank you.