PIAB ExceptionCallHandler: support methods with not-void return type

Topics: Policy Injection Application Block
Mar 6, 2007 at 11:49 PM
Hello,

I'm not sure that it's poossible to implement in PIAB for now and even it is already in a plan to be done perhaps, but I have added this to Issue Tracker as a poosible feature.

Now PIAB ExceptionCallHandler doesn't swallow exceptions for not void methods. Maybe it could be done configuring the default returning value in an attribute/config (depending on used MatchingRule)?

http://www.codeplex.com/entlib/WorkItem/View.aspx?WorkItemId=8714

Thanks!
Mar 7, 2007 at 12:28 AM
Thanks Leonid - this is an interesting suggestion, although it does sound a little dangerous! Can you think of any real-world examples where you would want this behavior?

thanks
Tom
Mar 7, 2007 at 2:48 PM
Yep, Tom :) At the first glance the possibility to change business rules (I suppose the primary target how people will try using VAB) from a local config sounds dangerous too...

I already had run into the problem that anyone can change rules for a desktop application and even change custom Validators that may incapsulate business rules in a single library to the others and I have no idea what rules were used when user used the application. But this is my another suggestion for VAB...


Regarding PIAB, I just had tried DAL scenario where we let's say have an Order like this:

public class Order {
public static Order Empty = new Order();

private Guid id = Guid.Empty;
public Guid Id {
get { return id; }
set { id = value; }
}

private string title = "Not defined";
public string Title {
get { return title; }
set { title = value; }
}
}

and a factory class where we can grab data from a data reader

public class OrderFactory {

public Order GetOrderFromDataReader( IDataReader reader ) {
Order order = new Order();

try {
// read
}
catch( Exception ex ) {
bool rethrow = ExceptionPolicy.HandleException( ex, "DAL" );
if( rethrow ) { throw; }

return Order.Empty;
}

return order;
}
}

and here we are able to rule DAL it should throw an exception upstairs or not.
The alternative using PIAB would look like this I think, so the returning value is hard-coded but the behaviour is configured and injected:

DIABTag( "CatchExceptionInDAL", "FullFriendly.Order.Empty" )
public Order GetOrderFromDataReader( IDataReader reader ) {
Order order = new Order();

// read

return order;
}

here the returning object is static. Maybe just a type, I guess it could work like Fault Contracts in WCF.

or returning boolean:

DIABTag( "CatchExceptionInDAL", "false" )
public bool DoesOrderExist( Order order )
{
// check
if( /* check */) { return true; }

return false;
}


Something like this...

Thanks!