Autor Beitrag
phoque
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starontopic star
Beiträge: 32



BeitragVerfasst: Mi 14.12.05 11:31 
Der Delphi Debugger gibt ja bei Exceptions eine Fehlermeldung aus z.B.
Zitat:
Cannot open File "D:\Data\...". Das System kann die angegebene Datei nicht finden.

Ist es jetzt irgendwie moeglich diese auszulesen um Sie in einer Datei abspeichern zu koennen? Ich wollte die dann anschliessend analysieren koennen. An den Namen der Exceptions komme ich wohl "EFopenError". Aber wie komme ich an die komplette Meldung?

Moderiert von user profile iconTino: Titel geändert.
chrisw
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starhalf ontopic star
Beiträge: 439
Erhaltene Danke: 3

W2K
D7
BeitragVerfasst: Mi 14.12.05 11:47 
ausblenden Delphi-Quelltext
1:
2:
3:
4:
5:
6:
7:
try
  OpenFile(..); //Bzw. der Befehl, der die exceptions auslöst !
except
  on EFopenError do //Einen fehler ins log schreiben (Bsp. Datei konnte nicht geöffnet werden)
  //oder
  on E: Exception do //E.Message enthält die Fehlermeldung; diese ins log schreiben
end;

_________________
Man sollte keine Dummheit zweimal begehen, die Auswahl ist schließlich groß genug.
phoque Threadstarter
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starontopic star
Beiträge: 32



BeitragVerfasst: Mi 14.12.05 12:05 
soweit klappt das schon ganz gut.
Kann ich das jetzt auch fuer die alle anderen Exceptions machen die im else teil aufgefangen werden?

ausblenden Delphi-Quelltext
1:
2:
3:
4:
5:
6:
7:
8:
on E: EFOpenError do
begin
  WriteLog(E.Message, Datum);
end;
else
begin
  WriteLog( ... , Datum);
end;


Moderiert von user profile iconraziel: Quote- durch Delphi-Tags ersetzt
chrisw
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starhalf ontopic star
Beiträge: 439
Erhaltene Danke: 3

W2K
D7
BeitragVerfasst: Mi 14.12.05 12:10 
Aus der Online Hilfe(OH)
ausblenden Delphi-Quelltext
1:
2:
3:
4:
5:
6:
7:
try
 ...
except
  on EZeroDivide do HandleZeroDivide;
  on EOverflow do HandleOverflow;
  on EMathError do HandleMathError;
end;

_________________
Man sollte keine Dummheit zweimal begehen, die Auswahl ist schließlich groß genug.
phoque Threadstarter
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starontopic star
Beiträge: 32



BeitragVerfasst: Mi 14.12.05 12:26 
Hmm, das verstehe ich nicht. Damit werden doch nur die speziellen Exceptions behandelt.
Ich suche eine Moeglichkeit, die Fehlermeldung auszulesen die eine beliebige Exception liefert.
Ich weiss ja vorher nicht unbedingt welche Exception kommt.
Also etwas in dieser Art:

ausblenden Delphi-Quelltext
1:
2:
on E: EFopenError do WriteLog(E.Message)
on E: AllOtherErrors do WriteLog(E.Message)


Moderiert von user profile iconraziel: Quote- durch Delphi-Tags ersetzt
Lossy eX
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starhalf ontopic star
Beiträge: 1048
Erhaltene Danke: 4



BeitragVerfasst: Mi 14.12.05 12:32 
Das hatte Chrisw als erstes bereits mit genannt. Exception ist die Klasse von der ALLE Exceptions abgelitten werden.
Also genügt folgendes.
ausblenden Delphi-Quelltext
1:
2:
3:
4:
5:
6:
try
  ...
except
  on E: Exception do 
    WriteLog(E.Message);
end;

_________________
Nur die Menschheit ist arrogant genug, um zu glauben sie sei die einzige intelligente Lebensform im All. Wo nicht mal das nachhaltig bewiesen wurde.
phoque Threadstarter
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starontopic star
Beiträge: 32



BeitragVerfasst: Mi 14.12.05 12:49 
joa, da hatte ich nur die spezielle Exception eingesetzt.
Jetzt klappt es :D