110,536
社区成员
发帖
与我相关
我的任务
分享
try
{
result = method.Invoke(instance, args);
}
catch (ArgumentException)
{
data = MessageFormatter.FromChannelMethodResult(null, "MethodParametersError");
Server.SendAsync(e.Client, data, e.Head);
return;
}
catch (Exception)
{
data = MessageFormatter.FromChannelMethodResult(null, "MethodRuntimeError");
Server.SendAsync(e.Client, data, e.Head);
return;
}
public static void testInvok()
{
Console.WriteLine("testInvok");
string str = "aaa";
int i = Convert.ToInt32(str);
}
public static void Main(string[] args)
{
try
{
typeof(Program).GetMethod("testInvok").Invoke(null, null);
}
catch (Exception)
{
Console.WriteLine("Exception");
}
}
//输出:
//testInvok
//Exception
可以看出来能够捕捉的,是不是你在函数里面处理了异常呢?