在WinForm编程中,如何截获所有未处理的Exception呢?(在WebForm中,可以在Page.Error事件中处理所有没有处理的异常,但WinForm的Form好像没有类似的事件啊!)
---------------------------------------------------------------
see
http://www.codeproject.com/dotnet/unhandledexceptions.asp
---------------------------------------------------------------
using System.Threading;
...
static void Main()
{
// Subscribe to thread (unhandled) exception events
// (Alternatively, could do this in Form_Load)
Application.ThreadException += new ThreadExceptionEventHandler(
Application_ThreadException);
// Load the form
Application.Run(new Form1());
}
public static void Application_ThreadException(
object sender, ThreadExceptionEventArgs e)
{
// Handle exception.
// The exception object is contained in e.Exception.
}
主要是Application.ThreadException 事件的使用