Delphi - Thread exception handling

0

I wrote a thread in Delphi with exception handling, but when the exception happens the operation is aborted and does not fall into the except block. Is there any specific handling 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;
    
asked by anonymous 04.01.2016 / 12:26

2 answers

1

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

    
07.04.2016 / 16:59
0

Add your code to make it clearer, but it's something like that.

procedure TSuaThread.Execute;
begin
  try
    ......
  except
    ... seu tratamento da exceção ...
  end;
end;
    
04.01.2016 / 12:28