gpt4 book ai didi

delphi - 如何在 Eurekalog 调用之前设置 e.message

转载 作者:行者123 更新时间:2023-12-02 15:16:11 24 4
gpt4 key购买 nike

我正在使用下面的代码尝试创建自定义错误消息以通过 EL 进行日志记录。该代码适用于记录我自己(即当 {ifNdef EUREKALOG} 时) - 在这种情况下,“(额外信息)”显示在 ShowMessage 中,但在调用 EL 日志记录时不会显示。在后一种情况下,将记录原始电子消息。有没有办法实现这个目标?

on e: exception do
begin
e := Exception(AcquireExceptionObject);
e.Message := '(Extra info) ' + e.Message;
{$if defined(EUREKALOG)}
// EExceptionManager.ExceptionManager.ShowLastExceptionData;
// OR
EBASE.HandleException(e);
{$else}
ShowMessage(e.message + ' I got this, thanks!');
{$endif}
ReleaseExceptionObject;
end;

最佳答案

前面的答案是正确的:EurekaLog在引发异常时捕获异常信息。它不知道您稍后更改了异常对象。你需要显式地告诉EurekaLog新的信息。例如:

uses
EException, // for TEurekaExceptionInfo
EExceptionManager; // for ExceptionManager

procedure TForm1.Button1Click(Sender: TObject);
{$IFDEF EUREKALOG}
var
EI: TEurekaExceptionInfo;
{$ENDIF}
begin
try
raise Exception.Create('Error Message');
except
on E: Exception do
begin
E.Message := E.Message + sLineBreak + 'Hello from except block';

{$IFDEF EUREKALOG}
EI := ExceptionManager.Info(E);
// Сould be NIL if EurekaLog is disabled or instructed to ignore this exception
if Assigned(EI) then
// Overrides both dialog and logs
EI.ExceptionMessage := E.Message;
// OR:
// Overrides only dialogs
// EI.AdditionalInfo := E.Message;
{$ENDIF}

raise; // or Application.ShowException(E);
end;
end;
end;

关于delphi - 如何在 Eurekalog 调用之前设置 e.message,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/44721048/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com