I want to write to any text file any exception that happens in the system.
I'm using the Application Events
component of the additional palette.
Below is an example of the code:
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;
The problem that in some screens of the systems is used the
try - except
, it displays the message and does not call the onException
event of the component.