I have an old Windows.Forms Application that I am trying to debug.
Sometimes after running a few minutes it will produce an ArithmeticException or an OverflowException. The source must be somewhere in the codebase, but the stacktrace always points to the line Application.Run(mainForm);
The StackTrace is useless as it only shows Windows.Forms native calls:
bei System.Windows.Forms.UnsafeNativeMethods.DispatchMessageW(MSG& msg)
bei System.Windows.Forms.Application.ComponentManager.System.Windows.Forms.UnsafeNativeMethods.IMsoComponentManager.FPushMessageLoop(Int32 dwComponentID, Int32 reason, Int32 pvLoopData)
bei System.Windows.Forms.Application.ThreadContext.RunMessageLoopInner(Int32 reason, ApplicationContext context)
bei System.Windows.Forms.Application.ThreadContext.RunMessageLoop(Int32 reason, ApplicationContext context)
bei System.Windows.Forms.Application.Run(Form mainForm)
bei Program.Main() in C:xyProgram.cs:Zeile 102.
To find the source of the exception I have added an exception handler to
System.Windows.Forms.Application.ThreadException
and to System.AppDomain.CurrentDomain.UnhandledException
.
I have tried enabling and disabling catching exceptions with
System.Windows.Forms.Application.SetUnhandledExceptionMode();
The ThreadException event handler is never called. The UnhandledException event handler just reports the same exception I see in Visual Studio.
In Visual Studio I have enabled breaking execution when an exception is thrown:
This had no effect whatsoever.
What can I do to find the offending line of code?
edit: the full exception details:
If I start the process without any debugger attached, and wait for it to crash before attaching a debugger, I get the following exception:
Unbehandelte Ausnahme bei 0x0c9f9e1b in program.exe: 0xC0000090: Floating-point invalid operation.
Debugging then leads to this piece of disassembly
0C9F9E12 add esi,10h
0C9F9E15 push 0CA1FD48h
0C9F9E1A push eax
0C9F9E1B fmul qword ptr ds:[0CA202E0h]
0C9F9E21 fstp dword ptr [esp+18h]
I cannot parse this, but I suspect this is merely the DispatchMessageW function
See Question&Answers more detail:
os