Delphi - Thread exception handling

Asked

Viewed 720 times

0

I wrote a thread on Delphi with exceptions treatment, but when the exception happens the operation is aborted and does not fall into the except block. Is there any specific treatment of exceptions within threads?

procedure TThreadEnvioJSONsWS.Execute;
var
  vErro: String;
begin
  try
    CoInitialize(nil);

    vSucesso := False;

    TSistema.retornaInstancia.adicionaMensagemLog('Iniciando a geração dos dados.', cOperacaoLog);

    if not(envioWSEmpresa(vErro)) then
      raise Exception.Create(vErro);

    if not(envioWSAparelhos(vErro)) then
      raise Exception.Create(vErro);

    if not(envioWSApontamentos(vErro)) then
      raise Exception.Create(vErro);

    if not(envioWSOperadores(vErro)) then
      raise Exception.Create(vErro);

    if not(envioWSRiguers(vErro)) then
      raise Exception.Create(vErro);

    if not(envioWSAparelhosOrdens(vErro)) then
      raise Exception.Create(vErro);

    vSucesso := True;
  except
    on e:Exception do
    begin
      vMensagemErro := 'Falha no envio das informações.'+ sLineBreak+     e.message;
      TSistema.retornaInstancia.adicionaMensagemLog(vMensagemErro, cOperacaoLog);
    end;
  end;

  CoUninitialize;
end;

2 answers

1

The problem was caused because the type of exception was not on "Exception", so do not fall into the block "on and:".

0

Add your code to make it clearer, but it’s something like this.

procedure TSuaThread.Execute;
begin
  try
    ......
  except
    ... seu tratamento da exceção ...
  end;
end;
  • 1

    yes, I do so, but when the exception explodes the routine is aborted and does not fall into the except block.

Browser other questions tagged

You are not signed in. Login or sign up in order to post.