我正在使用下面的代码尝试创建一个自定义的错误消息,以便通过EL进行日志记录。代码用于自己记录日志(例如,当{ifNdef EUREKALOG}时)-在这种情况下,‘(额外信息)’会显示在ShowMessage中,但不会在调用EL日志记录时显示。在后一种情况下,会记录原始e.message。有没有办法做到这一点?
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;发布于 2019-06-11 18:58:47
前面的答案是正确的: 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;发布于 2017-06-24 00:23:40
procedure TForm1.btnTryExceptELClick(Sender: TObject);
begin
try
ProcWithError;
except
on e: exception do
begin
e := Exception(AcquireExceptionObject);
try
e.Message := E.Message + '(Extra info) ';
{$if defined(EUREKALOG)}
raise Exception.Create(e.message); // with "extra info"
// if you really want to do this yourself (for no reason)
// EExceptionManager.ExceptionManager.ShowLastExceptionData;
// OR
// EBASE.HandleException(e);
{$else}
ShowMessage(e.message + ' I''ve got this, thanks!');
LogError(e.message);
{$endif}
finally
ReleaseExceptionObject;
end;
end;
end;
ShowMessage('After except');
end;https://stackoverflow.com/questions/44721048
复制相似问题