How can I find out which procedure threw an exception in Delphi?

后端 未结 3 1433
南笙
南笙 2020-12-15 09:03

I am using Delphi TApplication.OnException Event to catch unhandled exceptions

This works well but does not give sufficient information about where the exception hap

相关标签:
3条回答
  • 2020-12-15 09:43

    Mostly related: Exception Handling in Delphi.

    0 讨论(0)
  • 2020-12-15 09:58

    You can get the memory address where the exception was thrown by using the ExceptAddr variable (System unit). But if you want a stack trace you could use one of the 3rdParty tools MadExcept, EurekaLog or the open source JCLDebug (part of the JCL).

    0 讨论(0)
  • 2020-12-15 10:01

    The simplest and quickest way would be to use the JCL exception and debugging support. After installing the JCL, make sure to insert the debug symbols into the binary (Projects -> JCL debug expert -> Insert JDBG data for this binary -> Enabled) and add a JCL exception dialog to the project (File -> New... -> Dialogs -> Exception dialog).

    If the JCL installer fails to add that dialog to the object repository and it doesn't appear (happened to me a few times), either add it manually by copying the .pas and .dpr file from jcl-install-dir\experts\debug\dialog into your project and adding them manually, or close Delphi, edit %DELHPIDIR%\bin\delphi32.dro in a text editor and add something like this to it (adjusting the paths of course:)

    [P:\DELPHI11\EXTERNALLIB\JCL\EXPERTS\DEBUG\DIALOG\EXCEPTDLG]
    Type=FormTemplate
    Name=Exception Dialog
    Page=Dialogs
    Icon=P:\DELPHI11\EXTERNALLIB\JCL\EXPERTS\DEBUG\DIALOG\EXCEPTDLG.ICO
    Description=JCL Application exception dialog
    Author=Project JEDI
    DefaultMainForm=0
    DefaultNewForm=0
    Ancestor=
    
    [P:\DELPHI11\EXTERNALLIB\JCL\EXPERTS\DEBUG\DIALOG\EXCEPTDLGMAIL]
    Type=FormTemplate
    Name=Exception Dialog with Send
    Page=Dialogs
    Icon=P:\DELPHI11\EXTERNALLIB\JCL\EXPERTS\DEBUG\DIALOG\EXCEPTDLGMAIL.ICO
    Description=JCL Application exception dialog
    Author=Project JEDI
    DefaultMainForm=0
    DefaultNewForm=0
    Ancestor=
    
    0 讨论(0)
提交回复
热议问题