我使用由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。 –