Policy Injection Attributes Intercepted "some" of the time.

Topics: Policy Injection Application Block
May 14, 2009 at 4:56 PM

I've got a strange situation, not sure if it's my bug or the behaviour of PIAB.

I've got a method:

 

public void MyMethod(Obj myObj)

{

  DoSomethingTrivial();

  try {

    DoSomethingDBRelated();

    Database.Persist(myObj);

  } catch(Exception ex) { // handle exception via ExceptionHandling block}

}

 

Now, when I decorate "MyMethod" with the Exception call handler, everything works as expected. ie:

[ExceptionCallHandler("MyPolicy")]

public void MyMethod(Obj myObj)

{

  DoSomethingTrivial();

  DoSomethingDBRelated();

  Database.Persist(myObj);

}

I can remove the try catch from the method, and PIAB handles the exception with the given policy.

But the problem is, I don't want the entire method "MyMethod" to be wrapped in a try/catch.  The first part, DoSomethingTrivial() should be outside this handler.  So I changed my method to:

 

public void MyMethod(Obj myObj)

{

  DoSomethingTrivial();

  DBPersist(myObj);

}

[ExcpetionCallHandler("MyPolicy")]

public void DBPersist(Obj myObj)

{

  DoSomethingDBRelated();

  Database.Persist(myObj);

}

 

I was expecting that now only the second method will be handled by the Exception call handler.  Unfortunately, when implmented this second way, the call handler is NOT invoked.

Any pointers are appreciated.

 

May 15, 2009 at 11:47 AM

Hi,

Please see this post: http://entlib.codeplex.com/Thread/View.aspx?ThreadId=17407 , seems to be related.

Valiant Dudan
Global Technology & Solutions
Avanade, Inc.
entlib.support@Avanade.com