I have a console application with main method as follows:
public static void Main(string[] commandString)
{
try
{
var asm = Assembly.Load("CAT");
var t = asm.GetType("CAT",true,true);
var _Adjudication = Activator.CreateInstance(t);
t.InvokeMember("NAMEME", BindingFlags.InvokeMethod, null, _Adjudication, new object[] { "Fluffy", 5});
}
catch (Exception ex)
{
Environment.Exit(99);
}
}
CAT class is as below :
public class CAT
{
public void NAMEME(string name, int age)
{
try
{
throw new Exception();
}
catch (Exception ex)
{
throw ex;
}
}
}
I have an error stating "Exception was unhandled by user code" when I run this program. The error is caught by the Catch block of the NAMEME method.
How do I get the exception to hit the catch block of my Main method?
PS : I am using .NET Framework 4.0 PPS: I was able to handle it by capturing the TargetInvocationException error