2

我正在使用下面的代码尝试为 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;
4

2 回答 2

2

前面的答案是正确的: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;
于 2019-06-11T10:58:47.027 回答
1
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;
于 2017-06-23T16:23:39.780 回答