"<Program> has stopped working" explanation - delphi

Can someone explain me when Windows shows this message?
What do i have to do to stop my Program from throwing this exception?
I have a Delphi Windows Forms Program which throws this message short after doing some SQL operations.
So i do the SQL, everything seems fine at first, but at a random time after that windows is killing it by showing this message...
the intresting thing is, it only occours while debugging.
When i'm not debugging it's running perfectly stable.
EDIT: Using RAD-Studio2009
I dont want to turn off the message completely(Only hint i found by using Google)
i want to stop my program giving windows a Reason to do that.

Windows shows this message when an unhandled exception leaks out of your application. This is a fatal condition. Something very wrong has happened with your application because exceptions should all be caught.
You need to work out what is throwing the exception and why it is not being caught. The very first step is to expand the details of the error dialog and find out which module the fault is occurring in, what the fault is and so on. That should yield some high level clues at the very least.
Most likely the Delphi debugger will not be able to help you for such a fault. You need to configure your system to arrange for a crash dump to be produced by the Windows Error Reporting service. Then you can load up the error report in a tool like WinDbg and try to figure it out.

Related

DirectX12: dxgi dll catastrophic failure when creating IDXGIFactory

I'm attempting to initialize an IDXGIFactory4 using the CreateFactory2 function however this throws out an error:
onecore\windows\directx\database\helperlibrary\lib\perappusersettingsqueryimpl.cpp(121)\dxgi.dll!00007FFBA0D6D7F8: (caller: 00007FFBA0D4D167) ReturnHr(1) tid(64d8) 8000FFFF Catastrophic failure
onecore\windows\directx\database\helperlibrary\lib\perappusersettingsqueryimpl.cpp(98)\dxgi.dll!00007FFBA0D6D4D0: (caller: 00007FFBA0D3E221) ReturnHr(2) tid(64d8) 8000FFFF Catastrophic failure
onecore\windows\directx\database\helperlibrary\lib\directxdatabasehelper.cpp(999)\dxgi.dll!00007FFBA0D6D4FC: (caller: 00007FFBA0D3E221) ReturnHr(3) tid(64d8) 8000FFFF Catastrophic failure
I have not found any similar error messages online.
I have attempted running the function on its own and initializing as a different IDXGIFactory (e.g. IDXGIFactory2) instead but both still lead to the same issue.
ComPtr<IDXGIFactory> dxgiFactory;
UINT factoryFlags = DXGI_CREATE_FACTORY_DEBUG;
ThrowIfFailed(CreateDXGIFactory2(factoryFlags, IID_PPV_ARGS(&dxgiFactory)));
This is not the error as you describe it.
There is no real failure, there is no catastrophy, there is no even exception and there is no error code returned to you from the API call. What you are seeing is a glitch in internal API implementation that emits debug output with these strange lines. Apparently it is a small problem in Microsoft's API implementation and the weird format of the message suggests it comes from use of wil in one the modules: they probably intended to remove this output from Release build of the software but somehow it worked out in a different way and unintended debug output passed through...
The message is likely to correspond to recoverable internal error condition which is then handled and your API call ends up being successful. Nothing to worry about, it's just up to Microsoft to make things cleaner.
These errors happen even with any Blank app straight from the templates (or sample apps from Microsoft Github repos) in Visual Studio 2019 (v16.9.1). It's only annoying, apps never crash nor hang. However, this never happend before.
I hope Microsoft better fix this soon (it's bad for nerves and mental health). You can do nothing about it.

Attaching WinDbg to w3wp.exe causes IIS not to respond to requests

I am following the steps in this article for attaching WinDbg to IIS to find the root cause of an "External component has thrown an exception" error. I am using WinDbg 10 (from Windows 10 SDK) on a Windows 7 on an ASP.NET MVC .NET 4.6 (Visual Studio 2015) app. When I attach WindDbg to the w3wp.exe process, reload the web page, the browser just spins waiting for a response. As soon as I stop WinDbg, the response is received. Looks like WinDbg is stalling IIS for some reason. I have checked/unchecked the 'invasive' checkbox. I enabled/disabled CLR Exceptions. I am not professient in WinDbg.
Any ideas what might be the issue? Or other quick way to troubleshoot that kind of exception? I usually know the issue is a compile error in a partial view after spending some time but I am interested in learning WinDbg's way of finding it (if it can).
Attaching WinDbg will cause all threads to suspend. If that is the case, your command prompt looks like this, waiting for input:
At this time, if I understand the purpose of the linked article, you should enter things like
.symfix;.reload
.sxe clr
.loadby sos clr;.loadby sos mscorwks
To resume the threads and continue execution of the program, enter g. After that, the command prompt should change to
Now do something in your application and wait for an exception, then issue the commands mentioned in the article
!dumpheap -type CompilerError
!dumpobject <0xXXXX>
or (I would suggest)
!pe

How to track application strange behaviour?

One of my client has experience strange behavior of my application - on second time it runs - it just closing - no error or anything.
How can I track this kind of "heisenbugs" where I don't have any stack trace or physical access to the remote machine nor I can't recreate the behavior my client is describing?
on second time it runs - it just closing - no error or anything.
an error in a With... Do... Try...Finally...Free... maybe ? At the end it would close the appli instead of freeing the scoped object?
The Windows Debugger Tools provides a DbgSrv service which handles 'second change exceptions' and can generate an extensive report when it detects a selected executable runs but closes under a severe error or suspicious activity.

Trouble getting windows service to start

I'm having trouble getting a windows service to start. Each time it runs, in the IDE, as a service, or otherwise, an error shows up in the windows event log stating:
"The service process could not connect to the service controller."
When debugging, I can step through the ServiceCreate procedure, and I successful print to a log file there. However, I have identical code (save the message string) in the ServiceStart or ServiceExecute procedures and it never appears to run.
The debugger lets me step into Application.CreateForm, which jumps straight to the ServiceCreate procedure but I cannot step into Application.Run.
Any ideas?
Edit: To clarify, I am debugging by starting the windows service, then attaching to the process in Delphi during a wait that I added to start up.
Edit 2: Okay, it's now letting me step into Application.Run and more details where ever I want. I had turned off debug dcus. Thought stepping through the VCL code did nothing to help me see what the problem was. I still have no idea how ServiceStart or ServiceExecute are supposed to get called.
this is the only error message you receive? what code do you have in the initialization section of your pas files? this error is generally raised when an error is raised and your application doesn't catch it. try to log all the events from app. also, take a look into the Windows event viewer for more details related to this.

Debugging Delphi ISAPI Dll on Apache

I have run into a situtation where frequently when debugging a ISAPI Dll (TWebModule) running under Apache I get errors. The caption on the error box is "Debugger Fault Notification" and contained in the message is, among other things:
"c:\program files\Apache\bin\httpd.exe faulted with message......."
When this happens the cpu window pops up, and I have to hit the "OK" button on the error message. I might have to do this 3 - 5 times before program flow continues.
This is happening on my laptop. I have a desktop with the same exact configuration (as far as I know) and I don't have this problem. Both operating systems are XP. So obviously there is some setting or outdated file somewhere.
Also, I have noticed if first run my website when Apache is not in the debugging envrironment it seems not to have this problem. (i.e. start apache in the services, run my web app, stop the service, and then debug it within the Delphi environment).
Any ideas???
While it doesn't directly answer the how to debug using Apache, another alternate debugging technique which works well is to use idDebugger (near the bottom of that page). It will allow you to debug ISAPI DLL's directly from the IDE without having to start/stop services. I now never develop ISAPI DLL's without it.
To avoid this and other problems, I've started xxm. It's an alternative to TWebModule, and uses a separate wrapper to run with IIS, but there's also an Apache, FireFox and IE wrapper! It also uses mixed-HTML-Delphi-source and the development-mode wrappers do the parsing and an auto-compile to give a web-script-like environment.
Also the InternetExplorer plugin works great in the debugger (with iexplore.exe as host application).
Error code 0xC0000008 is Status_Invalid_Handle. That can be thrown by CloseHandle, for example, when you try to close a handle that either was never open or was already closed. The error might not occur when you're running outside the debugger because the API won't throw an exception unless it's being debugged.
If you're getting that exception in code that the debugger doesn't have access to, then the debugger will display the CPU window instead. Look at the call stack to find the place in your code closest to where the exception came from.
It's also possible that it's not occurring in your code at all. Try doing your same debug routine without your module installed. Do you still get errors?

Resources