I know how to catch exceptions in delphi (try..except/finally and e.message) but I want to know if there exists an exception handling mechanism which can raise the exception and also the name of the routine which raised it. by example
procedure/function bla();//this can be in a unit/class
begin
code....
an error is raised here -> inside or not of an try-except/finally block
end;
and I'll receive an message/object/anything that indicates me that error 'x' was raised in 'bla'.
I know about madexcept, there is another way to catch exceptions as they do?
I'm using Delphi 7. Solution may be applicable to other Delphi version also.
As others have stated...JCL has some nice features...
In your application...You need to set up some info to get the necessary Stack Frame for the Hook...
Project-->Compiler->Stack Frames...I also have all the Debugging checked and add the following...Project->Options->Linker->Map file(Select Detailed)/Include TD32 debug Info
In my Logger unit...I have this...You'll have to have your own TLogger...that saves the info for you...
Also look at JCLDebug's JCLLastExceptStackListToStrings() which gives you a nice stack dump of the point of exception.
And like TheNewbie noted: you get this by setting TApplication.OnException to be the address of your error handler.
EurekaLog is also an excellent tool, on par with MadExcept.
You can use the
ProcByLevel
function from theJclDebug.pas
unit wich is part of the JCL library.before to use you must activate the option
'Insert JDBG data into the binary'
from the Ide Menu tools->jcl Options.and then you can use it in this way
and the result is something like this
No, Delphi doesn't have any built-in "get the name of the current function" feature. MadExcept or similar products are probably the best way to get meaningful names in error reports.
MadExcept is the best solution I've found so far, of course, but if your needs are not too fancy and your project is commercial, then you should check Project JEDI's JCL (especially JclDebug.pas). There you'll find many helpful routines. It supports .MAP files, TurboDebugger symbols, etc. Also, with it you can embed the debug info (as with MadExcept).
You might also want to look into TApplication.OnException (and related).