我使用由AppDomain
提供的UndhandledException
,我所做的基本上是这样的:如何仅从UnhandledException中获取消息?
static void Main(string[] args)
{
AppDomain.CurrentDomain.UnhandledException += UnhandledExceptionTrapper;
}
static void UnhandledExceptionTrapper(object sender, UnhandledExceptionEventArgs e)
{
e.ExceptionObject.Message? <- there is no message
Console.WriteLine(e.ExceptionObject.ToString());
Console.WriteLine("Press a key for exit.");
Console.ReadLine();
Environment.Exit(1);
}
你怎么看我无法访问邮件属性,但如果我设置一个断点,我可以请参阅e
变量Message
属性,为什么我不能使用这个?
也许'如果(e.ExceptionObject是例外){((异常)电子投放。 ExceptionObject).Message; }' – Quantic
啊,所以我需要投它,让我试试。感谢提示! – IlDrugo
永远不会*,永远*,**永远不会**这样做。只有e.ExceptionObject.ToString()会产生一个合理的诊断,不会在场上抛出InnerException。 –