Getting values of method call from exception object

  • Thread starter Thread starter Guest
  • Start date Start date
G

Guest

Is there any way to get somehow values of method paramter
in which exception has been thrown

example

public void Foo(int ala, string ola

try
//..
throw new Exception()
//..

catch(Exception ex

LogExceptionData(ex)



public void LogExceptionData(Exception ex


tw.WriteLine(ex.Message)
if(ex.TargetSite!=null

tw.Write(ex.TargetSite.DeclaringType.Name)
tw.Write(".")
tw.Write(ex.TargetSite.Name)
tw.WriteLine("()")


//AND NOW, I would like to save values of the
//parameters of method in which exception has been throw

//Iterate through values collection, but how to get them
tw.WriteLine(....



I can get parameter type collecion, however I'd like to get their values

Thanks
Michał Januszczyk
 
----- Alvin Bruney [MVP] wrote: ----

what are you trying to accomplish? maybe there is an alternativ

I was trying to implement a nice error handler that would allow to service any typ
of exception, and would always be able to extract maximum available information for error
logging purposes (and subsequent debuging). Currentry, in order to get method parameters'
values I have to wrap original exception with my custom exception

public DoSomethig(int ala, string ola,...)

catch(Exception ex

throw new MyCustomException("Parameters values: ala="+ala+", ola="+ola+", ....", ex)


This forces me to write for each method its own particular {parameter description string retrieval routine
I can do with this, however it would be nice to have an automat, that would do this for me. :-

-
Regards
Michał Januszczyk
 
Back
Top