Custom ExceptionHandler & Policy Injection App

Topics: Exception Handling Application Block, Policy Injection Application Block
Apr 2, 2009 at 4:54 PM
Hi,

How could I retrieve the input parameters of a method when a exception ocurrs?

I created a new policy to catch all exception without add try catch blocks in the source code. This policy would be managed by a Custom Exception Handler, but I am not able to know the value input parameters where the error ocurred. I have the method name, namespace, message error, but we would need some informacion like the value input parameters. Is there any way to get them?

Thanks
Apr 3, 2009 at 7:39 AM
The input parameters are available in the IMethodInvocation input parameter in the Invoke method of your custom handler.  You can access them through the Arguments property.


Sarah Urmeneta
Global Technology & Solutions
Avanade, Inc.
entlib.support@avanade.com
Apr 3, 2009 at 9:59 AM
Hello,
I followed these steps:
1. I created a new custom exception handler implementing IExceptionHandler interface.
2. I added the Exception Handling Application Block to my config file and added a new Policy called "Mypolicy" to catch all type Exception
3 I defined that this policy was managed by the custom exception that was created in the step 1.
4 I added the Policy Injection Application Block to may config file and created a new policy. As "Handlers" I selected "Exception Handling Handler" and defined "Mypolicy" as ExceptionPolicy in the atributes of the "Handlers"
When I run the aplication and create a new exception, the custom exception handler that was created catch the exception through the HandleException method, but this method has not access to the input parameters value.
----- Original Message -----
From: [email removed]
To: [email removed]
Sent: Friday, April 03, 2009 9:39 AM
Subject: Re: Custom ExceptionHandler & Policy Injection App [entlib:52098]

From: AvanadeSupport

The input parameters are available in the IMethodInvocation input parameter in the Invoke method of your custom handler. You can access them through the Arguments property.


Sarah Urmeneta
Global Technology & Solutions
Avanade, Inc.
entlib.support@avanade.com
Apr 3, 2009 at 10:21 AM
Oh I see, you created a custom exception handler.  I thought you created a custom handler.  You really don't have to those info inside a custom exceptionhandler.  What I could think of right now is you could create a custom handler which would behave like an exceptioncallhandler.  You could base your code with that of the ExceptionCallHandler from the PolicyInjection.CallHandlers but before you pass the exception to the HandleException, add the input parameters (from the IMethodInvocation  parameter) to the Data property of the exception.  Modify then  your existing exception handler to access those.


Sarah Urmeneta
Global Technology & Solutions
Avanade, Inc.
entlib.support@avanade.com