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

时间:2017-06-23 12:04:58

标签: delphi eurekalog

我正在使用下面的代码尝试创建一个用于EL记录的自定义错误消息。该代码适用于自己记录(即{ifNdef EUREKALOG}) - 在这种情况下,'(Extra Info)'显示在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;

2 个答案:

答案 0 :(得分:0)

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;

答案 1 :(得分:0)

先前的答案是正确的: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;