How should I re-raise a Delphi exception after logging it?

前端 未结 8 1295
攒了一身酷
攒了一身酷 2021-01-01 10:40

Do you know a way to trap, log, and re-raise exception in Delphi code? A simple example:

procedure TForm3.Button1Click(Sender: TObject);
begin
  try
    rais         


        
8条回答
  •  渐次进展
    2021-01-01 11:33

    Old topic but, what about this solution?

    procedure MyHandleException(AException: Exception);
    begin
      ShowMessage(AException.Message);
      AcquireExceptionObject;
      raise AException;
    end;
    
    procedure TForm1.Button1Click(Sender: TObject);
    begin
      try
        raise Exception.Create('Bum');
      except
        on E: Exception do
          MyHandleException(E);
      end;
    end;
    

    It's based on the first code posted by Eduardo.

提交回复
热议问题