I have given to maintain a project in delphi for which I don't have a clue :). It was converted to XE8 from D5. So it has a lot of custom things ( I am replacing some custom Object lists with Dictionaries since Dictionaries didn't exist in D5). The main application is extending TForm and in the FormCreate method contains this line
Application.OnException := FormException;
HandleException := Application.HandleException;
The FormException method takes the exception and also prints a detailed window with some info and the call stack.
I want to integrate EurekaLog or madExcept in my project to be able to find more info on unhandled exceptions. But although installed and enabled I don't get the the window with the info I want. It runs the FromException method, although I read that when linking with madExcept this gets ignored. Creating a new project simply throwing an exception from a button click with madExcept or EurekaLog activated works properly. I don't know where to look for the exception handling of delphi, and whether I need to have more settings for 3rd party tools. Any ideas?
I use EurekaLog and there are a couple of cases that it doesn't capture the exceptions.
For example, if your app is multi-threaded and it is closing, threads are shutting down and it may happen that EL will not have the time to capture the exception.
You may also have configured EL to ignore specific exceptions. Check the options in the EL settings window.
Make sure that EL is configured for the type of app you have (VCL/FMX/etc.). This is the first option in the EL options windows.
Make sure that the debugger produces detailed map file (Project>Options>Compiler>Linking>Map file --> Detailed)
The last thing I can think of is EL is not properly installed. Go to Project>View Source. If EL is activated for your project, you should be able to see a number of units (EMemLeak, etc....) before the System.StartUpCopy.
BTW, which version of EL do you have?
Elpizo na boithisa...
EurekaLog see that you have installed Application.OnException event handler and assumes that you want to handle unhandled exceptions by yourself. The similar may be true for madExcept.
If you want to use EurekaLog to handle unhandled exceptions, you can either:
Explicitly call EurekaLog from your FormException by calling HandleException from EBase unit
Move your code from VCL's Application.OnException to EurekaLog's OnExceptionNotify.
See this for more details.
Related
While testing my delphi application, some Exceptions are raised but the debugger is not showing where (like it used to). Is there a setting which is causing this?
EDIT: When an exception occurs, a message appears alerting me to the fact that an error has occurred and what type of exception it is. Normally, I would be able to click 'break' and it would show me at which line the error had occurred, but when I click break, this doesn't happen.
It might help if you post a screen shot of what you actually do see before and after clicking Break.
And you haven't really answered the very first comment on your question: "What errors are occurring?" The point is if it's specific exceptions that aren't showing the code - they may be occurring in an external DLL.
As a first step check if Delphi will show the exception in the most simple case:
Drop a button on your form.
Write an OnClick handler with the following code: raise Exception.Create('This is a test');
NOTE Make sure you try this in both your existing app, and in a brand new stand-alone app.
If Delphi doesn't show you that exception in the simple app, I'd be very surprised, and some more serious digging will be required.
If it is shown in the simple app, but not in yours, then there's some specific problem in your project:
Ensure you aren't disabling debug info {$D-} or {$DEBUGINFO OFF} somewhere in your project.
You might have exception hooking code in your project that is somehow interfering. Try disabling exception loggers and similar tools to narrow down the problem. (Don't forget to re-enable the appropriate tools once the issue is resolved.)
Verify that your search and browsing paths are correctly configured to find the source code in order to show you the error.
If the simple exception is shown in both apps, then we'll probably need to know exactly what exceptions aren't showing to help further. However, here are a few more pointers (^s):
Go to Tools | Options. Under Debugger Options, look for Native OS Exceptions. Verify you haven't changed any of these settings.
When the exception occurs, open your Thread Viewer, and check if the the exception was raised on the main thread or another thread.
Also open your Call-stack Viewer, and verify you actually do have a call-stack.
Then check if Delphi will show the code for any of the call-stack lines.
NOTE There is still the possibility that Delphi is simply unable to find the source unit depending on where the exception is raised. However, Delphi is supposed to prompt you and ask where it can load the file from in such situations. (It definitely worked in older versions of Delphi.)
But I wouldn't rule it out because a buggy plugin might well be suppressing the prompt.
You can control the reaction of the debugger on exceptions from within the options.
Go to Tools\Options.
Click on the Debugger Options, then on language exceptions.
You probably have unchecked "Notify on language exceptions".
Else you can enable as much as possible.
Be sure to enable all debug information in your project:
Debug information
Symbol reference info
And try without optimizing.
I know I can use the IDE settings in Delphi Pro 6 to stop the IDE from intercepting and handling Delphi Exceptions (stopping the program and entering Debug mode), but unfortunately that turns off that handling for all Exceptions. The Access Violation Exception is happening in a DLL that I don't have the source code for. I was wondering if there is a conditional symbol I don't know about that I could define/undefine around the offending code block so at least I could turn off Exception handling around that code block. If not, perhaps some trick or technique to do so?
Compiler directives control how the compiler and linker turn your source code into executable code. Debugging instructions aren't stored in the DCU or the binary, so compiler directives can't control what you're after.
There are several ways to control exception handling. I've described them in an article I wrote a few years ago:
Use "advanced breakpoints" to define where the debugger should start or stop interrupting on exceptions.
Define certain exception classes that the debugger will always ignore.
Disable stopping on exceptions.
Disable debugging altogether.
When an application is run from within the IDE and the debugger is attached the exception 'External exception C0000008' is raised when it tries to connect to an imported ActiveX control.
If the application is ran standalone or the Rad Studio options/ Debugger Options/ Integrated debugging is unchecked, the program works as expected, no exception and the ActiveX control returns the expected result.
There are other ActiveX controls in the project, all of which work fine.
I have tried:
- Reinstalling the ActiveX control
- Re-Importing the ActiveX control
- Removing any software that may be causing conflicts (experts/ plug-ins etc)
- Turning off most running applications and services etc in case they are causing a conflict
Searching Google, It looks like others have been experiencing the same problem, but there is no fix to be found (other than turn off Integrated debugging, but obviously that is not a valid option.
Does any one have any ideas were to look to fix this problem?
I am using Delphi 2007
C0000008 is the status returned for an invalid handle. Make sure that your wrapper when it goes to create the object gives it a proper handle and not nil (assuming it is crashing because of a windows handle).
Since the application runs fine when not attached to the debugger, I'm assuming that the wrapper is handling this condition gracefully so the error is most likely occurring inside a try/except block.
It's a combination of non-obvious function behavior and IDE options.
MSDN CloseHandle
If the application is running under a debugger, the function will throw an exception if it receives either a handle value that is not valid or a pseudo-handle value. This can happen if you close a handle twice, or if you call CloseHandle on a handle returned by the FindFirstFile function instead of calling the FindClose function.
So there's two options - either check the code for a place where some invalid handle is being closed or turn off IDE's notification of this exception. Go to Tools > Options > Debugger options > Emb debuggers > Native OS exceptions, find Invalid Handle item and change On resume option to Run handled. This worked for me.
Credits for this solution go to _Vasilisk_ from sql.ru forum.
When I'm running my COM Office add-in from within the Delphi 5 IDE (using any of the office applications as the host), breakpoints work fine (when using remote debugging symbols and a properly set output folder), but none of the non-delphi exceptions (like access violations) in my code triggers the IDE to break at that point. In stead, the IDE stops at the manual re-raise in the try...except wrappers in any of my outer safecall methods.
I noticed that for some reason the DebugHook global was set to 0 (while as far as I know it should always be set to 1 when running from within the IDE). Moreover, setting it to 1 manually during the initialization of my DLL actually fixes the issue: the IDE now neatly stops at the line where my experimental (read: crappy) code triggers the exception.
The questions is: why? Why do I need to do this manually? Shouldn't the IDE set this for me? Did I forget a major important setting somewhere triggering this behaviour?
If for some reason the Delphi evaluator is unable to lookup the DebugHook global, it would be unable to set that value. Try to compile/run the DLL from the IDE and set the "host application" in the Run|Parameters dialog to the the Office app you intend to call your DLL from. It is possible that this may be a bug in how the evaluator uses the remote debug symbols.
In recent versions of Delphi there's an Option under Debugger for "Debug spawned processes" or something to that effect. Is that option present in Delphi5, and is it set?
Not sure whether this will help, because I have not encountered the behavior you describe.
I opened a project (created in D2007/08) in D2009 and it would compile but throw tons of exceptions when executed. Strange thing, but I know the project's a mess, so I want to go ahead and fix it. Well, not really fix all of it, just make it work would be enough.
When I ran it, I got some Debugger Exception Notification (the little message dialogue with Break, Continue, Help buttons) and I wanted to proceed and see if would perhaps work when skip over the exception. I checked the little "Ignore this exception type" check box in the bottom left corner and clicked Continue. Now I no longer get the Exception Notification, but the application still doesn't run. I just get a couple of vague error boxes and have very little idea what's going on.
I would like to re-enable the exception type I previously selected to be ignored. But I can't find the option anywhere. Where should I look for this? Can anyone help?
I have found the ignored exception types in
(Main menu) Tools >> Options >> Debugger Options >> CodeGear Debuggers >> Language Exceptions >> and there is the list of exception types ignored.
It's somewhat more hidden than in D2005 but very close to what was said in the article referenced by Stuart Dunkeld.
The following is extracted from this page on the Delphi Q&A by Rob Kennedy: (CC licensed) although it relates to Delphi 2005 it may help.
Why do I continue getting error messages even after I have written an exception handler?
In its default settings, the Delphi IDE notifies you whenever an exception occurs in your program, as in Figure 1. What’s important to realize is that at that point, none of your program’s exception-handling code has run yet. It’s all Delphi itself; its special status as a debugger allows it to get first notification of any exception in your program, even before your program knows about it.
Avoiding notification
If you do not want to be notified when an exception occurs, you have a few options.
You can use Delphi’s “advanced breakpoints” to disable exception handling around a region of code. To begin, set a breakpoint on the line of code where you want the IDE to ignore exceptions. Right-click on the breakpoint dot in the gutter and open the breakpoint-property dialog. In the advanced section are some check boxes. (See Figure 2.) Clear the “Break” box to prevent the debugger from interrupting your program at that line, and set the “Ignore subsequent exceptions” box.
Afterward, set another breakpoint where you want the debugger to resume handling exceptions. Change its properties to handle subsequent exceptions.
You can tell the debugger to ignore certain kinds of exceptions. Figure 3 shows Delphi’s language-exception options. Add an exception class to the list, and all exceptions of that type and of any descendant types will pass through to your program without Delphi interfering.
In an option related to the previous one, you can tell the debugger not to interrupt on any exceptions. To do that, clear the “Notify on language exceptions” check box.
Finally, you can turn off integrated debugging altogether. Delphi will not notify you of exceptions, and it will also not stop at breakpoints or allow use of the “Pause” button. Turn off integrated debugging in the debugger options, as shown in Figure 5 for Delphi 2005.