16

Delphi 2007(Win32)のエラーダイアログにスタックトレースを表示したいのですが。

理想的には、私はこのようなものが欲しいです:

try
  //do something
except on e : exception do
  begin
    //rollback a transaction or whatever i need to do here       
    MessageDlg('An error has occurred!' + #13#10 +
                e.Message + #13#10 +
               'Here is the stack trace:' + #13#10 +
               e.StackTrace,mtError,[mbOK],0);
  end;  //except
end;  /try-except

また、出力をIDEのコールスタックのようにするには、次のようにします。

MYPROGRAM.SomeFunction
MYPROGRAM.SomeProcedure
MYPROGRAM.MYPROGRAM
:7c817067 kernel32.RegisterWaitForInputIdle + 0x49
4

3 に答える 3

23

madExceptには、それを行うメソッド StackTrace (ユニット madStackTrace 内) があります。

JEDI Code Libraryは、ユニット JclDebug で同様の機能を提供します。

于 2008-11-03T14:24:50.853 に答える
9

私たちはExceptionalMagicを使用しており、それは私たちにとって本当にうまく機能します。これを使用すると、次のようなことができます。

try
    raise Exception.Create('Something bad happened...');
except
    on e: Exception do begin
        CallStack := TStringList.Create;
        try
            ExceptionHook.LogException; // Logs call stack
            ExceptionHook.CallStack.Dump(CallStack);
            ShowMessage(CallStack.Text);
        finally
            CallStack.Free;
            end;
        end;
    end;

これにより、かなり詳細な呼び出しスタックが生成されます。

Exception 'Exception' in module BOAppTemplate.exe at 003F3C36
Something bad happened...

Module: BOAppUnit, Source: BOAppUnit.pas, Line 66
Procedure: MyProcedure

Call stack:
:007F4C36 [BOAppTemplate.exe] MyProcedure (BOAppUnit.pas, line 66)
:7C812AFB [kernel32.dll]
:007F4C36 [BOAppTemplate.exe] MyProcedure (BOAppUnit.pas, line 66)
:00404DF4 [BOAppTemplate.exe] System::__linkproc__ AfterConstruction
Recursive call (2 times):
:007F4C36 [BOAppTemplate.exe] MyProcedure (BOAppUnit.pas, line 66)
:007F4CE6 [BOAppTemplate.exe] MyProcedure (BOAppUnit.pas, line 79)
:007F4D22 [BOAppTemplate.exe] Boappunit::TBOAppForm::Button1Click (BOAppUnit.pas, line 82)
:004604C2 [BOAppTemplate.exe] Controls::TControl::Click
:004487FB [BOAppTemplate.exe] Stdctrls::TButton::Click
:004488F9 [BOAppTemplate.exe] Stdctrls::TButton::CNCommand
:0045FFBA [BOAppTemplate.exe] Controls::TControl::WndProc

Exceptional Magicはソースなしでたったの25ドルなので、比較的安価です。お役に立てば幸いです。

于 2010-02-18T12:11:30.440 に答える
5

「 Delphi 2009 以降の新しい例外クラス」という記事に興味があるかもしれません。

于 2010-05-05T12:41:23.380 に答える