I Test-Code,Behandeln Sie alle Gewinde Ausnahme in WinForms
verfolgt habenprivate void button3_Click(object sender, EventArgs e)
{
Thread obj = new Thread(exception);
obj.Start();
}
void exception()
{
try
{
int i = 0;
int k = i/i;
}
catch (Exception ex)
{
throw ex;
}
}
private void button4_Click(object sender, EventArgs e)
{
int i = 0;
int k = i/i;
}
Und mein Hauptcode ist wie dieser
[STAThread]
static void Main()
{
Application.ThreadException += Form1_UIThreadException;
Application.SetUnhandledExceptionMode(UnhandledExceptionMode.CatchException);
AppDomain.CurrentDomain.UnhandledException += CurrentDomain_UnhandledException;
Application.EnableVisualStyles();
Application.SetCompatibleTextRenderingDefault(false);
Application.Run(new Form1());
}
private static void Form1_UIThreadException(object sender, ThreadExceptionEventArgs e)
{
MessageBox.Show("Exception");
}
private static void CurrentDomain_UnhandledException(object sender, UnhandledExceptionEventArgs e)
{
// MessageBox.Show("Exception UI");
}
Auch habe ich behandelt sowohl die Ausnahmen Anwendung auf Thread Ausnahme abstürzt.
Ob eine Korrektur muss ich auch für Handle Thread Ausnahme tun?
Möglicherweise * "Verwenden Sie den UnhandledException-Ereignishandler, um Ausnahmen einzufangen, die in Threads auftreten, die nicht von Windows Forms erstellt und gehört werden." * Https://msdn.microsoft.com/en-us/library/system.windows.forms .application.threadexception (v = vs.110) .aspx –