Capturar todos os erros do sistema

Delphi

13/05/2016

Estou querendo gravar em um arquivo texto qualquer exceção que acontecer no sistema.

Estou utilizando o componente Application Events da paleta additional.

Abaixo segue o exemplo do codigo:

procedure TfmPrototipo.ApplicationEventsException(Sender: TObject;

E:Exception);
var
NomeArquivo: string;
Arquivo: TextFile;

begin

NomeArquivo := ChangeFileExt(Application.Exename, '.log');
AssignFile(Arquivo, NomeArquivo);
if FileExists(NomeArquivo) then
Append(arquivo)
else
ReWrite(arquivo);
try
WriteLn(arquivo, 'Data: '+ DateTimeToStr(Now));
WriteLn(arquivo, 'Erro: ' + E.Message );
WriteLn(arquivo, '------------------------------------------- ');
Application.ShowException(E);
finally
CloseFile(arquivo);
end;

end;

O problema que em algumas telas do sistemas é utilizado o try - except, o mesmo apresenta a mensagem e não chama o evento onException do componente.
Ariel

Ariel

Curtidas 0
POSTAR