Autor Beitrag
Mandi Nice
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starontopic star
Beiträge: 29

Win2K, XP, CE
Delphi 2006 Prof.
BeitragVerfasst: Di 04.01.11 22:52 
Hallöchen

Hab' jetzt länger nix mehr gemacht in Delphi. Bin daher etwas eingerotet ;-(

Wie kann ich bei try finally feststellen ob eine Exception aufgetretten ist oder ob finally "normal" aufgerufen wurde.

Danke.

hmg
Mandi
Bergmann89
ontopic starontopic starontopic starontopic starontopic starontopic starofftopic starofftopic star
Beiträge: 1742
Erhaltene Danke: 72

Win7 x64, Ubuntu 11.10
Delphi 7 Personal, Lazarus/FPC 2.2.4, C, C++, C# (Visual Studio 2010), PHP, Java (Netbeans, Eclipse)
BeitragVerfasst: Di 04.01.11 23:15 
Hey,

so einfach geht das nicht, am bessten "verbaust" du 2 try-Blöcke. Dann hast du sozusagen einen Try-Except-Finally-Block:
ausblenden Delphi-Quelltext
1:
2:
3:
4:
5:
6:
7:
8:
try try

except

end;
finally

end;


MfG Bergmann.

_________________
Ich weiß nicht viel, lern aber dafür umso schneller^^
elundril
ontopic starontopic starontopic starontopic starontopic starontopic starhalf ontopic starofftopic star
Beiträge: 3747
Erhaltene Danke: 123

Windows Vista, Ubuntu
Delphi 7 PE "Codename: Aurora", Eclipse Ganymede
BeitragVerfasst: Di 04.01.11 23:53 
wann zieht Delphi da eigentlich nach und macht ein:

ausblenden Delphi-Quelltext
1:
2:
3:
4:
5:
6:
7:
try
{...}
finally
{...}
except
{...}
end;


lg elundril

_________________
This Signature-Space is intentionally left blank.
Bei Beschwerden, bitte den Beschwerdebutton (gekennzeichnet mit PN) verwenden.
jaenicke
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starofftopic star
Beiträge: 19346
Erhaltene Danke: 1754

W11 x64 (Chrome, Edge)
Delphi 12 Pro, C# (VS 2022), JS/HTML, Java (NB), PHP, Lazarus
BeitragVerfasst: Mi 05.01.11 00:35 
Ich glaube nicht, dass das kommen wird. Denn ein try..finally dient in der Regel als Resourcenschutzblock, während try..except dem gezielten Abfangen einer Exception in einem Teil des Quelltextes dient.

Eine Kombination ist deshalb gar nicht so sinnvoll. Klar gibt es auch Fälle, in denen es tatsächlich sinnvoll ist, den ganzen try..finally Bereich mit try..except abzudecken. Aber meistens ist es IMHO sinnvoller das try..except feiner abzustimmen (z.B. auf eine bestimmte Zeile zu begrenzen) um eine genauere Fehlerbehandlung zu erlauben.