Home > Mobile >  Get Delphi exception line
Get Delphi exception line

Time:09-14

I'm using Delphi 11. Considering this example code :

try
raise exception.create('Test');
except
on e : exception do
begin
showmessage(e.message ' on form X, line Y');
end;
end;

Is there a way to get the exact form X and line Y where the exception occured ?

CodePudding user response:

I would recommend madExcept: it's free for personal use but not for commercial use. It is very configurable and allows the user to send a bug report.

dialog on unhandled exception

From madshi > Help > madExcept:

The usual customer doesn't really want to read madExcept's detailed bug report. He just wants to send the bug report to the programmer, hoping that this will lead to a corrected new version. So in the default settings madExcept's box doesn't show any exception information, not even the exception message itself. The customer can just mail the bug report, or he can continue, restart or close the application.

One thing should be mentioned here: madExcept's exception box is not using any VCL stuff, instead it's build on pure win32 API calls. It's no fun designing a nice box with bitmap buttons and so on with win32 APIs only, but in this case it was absolutely necessary. The VCL is not thread safe, but our exception box must be able to show up in the context of each thread - thus it has to be thread safe, thus it must not use the VCL.

Apart from pure exception handling madExcept does one more thing (if you want it to), namely checking whether the main thread is frozen or not. Sometimes your program doesn't react anymore, although no exception occured. That can happen e.g. if your main thread runs in an infinite loop or if there's a bug in the synchronization of multiple threads, with the result of a dead lock. Such a bug can be very difficult to find, because your program is just frozen, without showing an exception. But with madExcept the situation is not that hopeless anymore: If your main thread doesn't react on messages for a specified time, madExcept raises an exception in the context of the main thread. In the resulting bug report you can see what the main thread was doing exactly and also what all other threads were doing at that time. That should help a lot finding infinite loop and dead lock bugs.

I am not associated with madshi.

CodePudding user response:

No, there isn't. Not using plain Delphi. Delphi doesn't have the __FILE__ or __LINE__ macros that C/C have.

You can get such info in your reports using an add-on exception handler, like EurekaLog.

  • Related