How do I get the source of an exception in my Application.OnException event handler?

302 Views Asked by At

In Delphi 7, if I catch an exception in my Application.OnException event handler, then how can we find out which function or procedure of the application threw this unhandled exception?

I have created an application and am getting the exception correctly, but how I can print the method name that caused this exception?

1

There are 1 best solutions below

0
On

That's not something that can easily be done. You need to hook into the low-level exception handling routines to obtain reliable stack traces. This is a very advanced topic. It requires reverse engineering of the runtime library. Not something that can reasonably be explained in detail in a Stack Overflow question.

There are a number of existing third party tools that offer such capabilities: madExcept, EurekaLog and JclDebug. I only have experience of madExcept which I endorse enthusiastically. However, the other toils are, by all accounts very good too.

If you want to learn how to do this, then look at JclDebug which is open source. If you don't require learning and just wish to add the capabilities to your program, evaluate and pick one of the tools. JclDebug is perhaps a little harder to integrate into your program so if you are looking for a quick and easy route forward, one of the other two may be more rewarding.