See following code for a specific approach:
using System;
using System.Text;
using System.Reflection;
using System.Collections;
using System.Diagnostics;
namespace exceptiondebug
{
class Program
{
public static void EronousMethod(string str, string str1, int integerValue)
{
try
{
throw new Exception("Some error");
}
catch (Exception ex)
{
ex.Data["str"] = str;
ex.Data["str1"] = str1;
ex.Data["integerValue"] = integerValue;
throw;
}
}
public static void Main(string[] args)
{
try
{
EronousMethod("foo","bar",40);
}
catch (Exception ex)
{
StringBuilder sb = new StringBuilder();
foreach (DictionaryEntry pair in ex.Data)
{
sb.Append(String.Format("{0}:{1}\n",pair.Key, pair.Value.ToString()));
}
Console.WriteLine(sb.ToString());
}
}
}
}
You can adapt it to your needs. As I know, there is no direct way, to retrieve (enumerate) runtime parameter values, thus you need to fill
Data property for every watched function.
A more general approach is described here:
http://stackoverflow.com/questions/2405230/can-i-get-parameter-names-values-procedurally-from-the-currently-executing-funct[
^] using PostSharp. You can use this approach, to store context of the watched method somewhere, and log it if needed. But as I said it is a considerable overhead.
It would be great if somebody would know a way, to enumerate or retrieve method parameters by name, at runtime even from inside the method itself.